Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LRUCache.copy aliases the wrong deque object methods #843

Closed
rsiemens opened this issue Apr 23, 2018 · 0 comments · Fixed by #1090
Closed

LRUCache.copy aliases the wrong deque object methods #843

rsiemens opened this issue Apr 23, 2018 · 0 comments · Fixed by #1090
Labels
bug
Milestone

Comments

@rsiemens
Copy link
Contributor

@rsiemens rsiemens commented Apr 23, 2018

Playing around with the LRUCache I noticed a issue with copying. Seems to be a small issue with forgetting to call post LRUCache._postinitafter copying the deque. Not sure if this is being felt elsewhere as I couldn't quickly see any instances of the cache being copied.

Expected Behavior

Performing __setitem__ on a copied (copy.copy or LRUCache.copy) should remove the oldest item from the cache.

Actual Behavior

Throws Index Error: pop from an empty deque

Full Traceback

>>> from jinja2 import utils
>>> cache = utils.LRUCache(1)
>>> cache['foo'] = 'bar'
>>> copy = cache.copy()
>>> copy['blah'] = 'blargh'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "jinja2/utils.py", line 424, in __setitem__
    del self._mapping[self._popleft()]
IndexError: pop from an empty deque
>>> copy._popleft
<built-in method popleft of collections.deque object at 0x10160d670>
>>> copy._queue.popleft
<built-in method popleft of collections.deque object at 0x101635360>

Your Environment

Python version: 2.7
Jinja version: 2.11.dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.