Whole file

msiemens/tinydb

The author described this change as Don't add keys to LRU cache if lookup fails (closes #87). It counts as a record because the check below fails on the code as it stood at 1f411be06 and passes on 7af4bf50c, with nothing else changed between the two runs.

Fix saved2016-01-03
Sharing licenceMIT · LICENSE
Change size+5 3

What the code was meant to do, written into the code itself as a save note

Don't add keys to LRU cache if lookup fails (closes #87)

The change

2929
3030 def refresh(self, key):
3131 """
32- Push a key to the head of the LRU queue
32+ Push a key to the tail of the LRU queue
3333 """
3434 if key in self.lru:
3535 self.lru.remove(key)
3636 self.lru.append(key)
3737
3838 def get(self, key, default=None):
39+ item = super(LRUCache, self).get(key, default)
3940 self.refresh(key)
4041
41- return super(LRUCache, self).get(key, default)
42+ return item
4243
4344 def __getitem__(self, key):
45+ item = super(LRUCache, self).__getitem__(key)
4446 self.refresh(key)
4547
46- return super(LRUCache, self).__getitem__(key)
48+ return item
4749
4850 def __setitem__(self, key, value):
4951 super(LRUCache, self).__setitem__(key, value)

The check that tells the two apart

failpass·tests/test_utils.py::test_lru_cache

Check file tests/test_utils.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it1f411be06776f8647be7549af94c28ef2d3cdac6
Broken version dated2015-12-31
Moduletinydb.utils
Units changedLRUCache
Fingerprint9ae6be54afd5b53c
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in msiemens/tinydb