Skip to content

Fix Deque maxlen enforcement when reopening persisted data - #396

Open
Harshit-2118 wants to merge 2 commits into
grantjenks:masterfrom
Harshit-2118:fix/deque-reopen-maxlen-395
Open

Harshit-2118 wants to merge 2 commits into
grantjenks:masterfrom
Harshit-2118:fix/deque-reopen-maxlen-395

Conversation

@Harshit-2118

Copy link
Copy Markdown

Fixes #395.

Reopening a populated Deque with a smaller maxlen currently leaves the persisted contents over the limit, and subsequent appends never bring it back within the bound. Apply the existing transactional maxlen setter in both Deque.__init__ and Deque.fromcache before extending the supplied iterable, so older items are discarded from the left immediately. For the issue's example, reopening yields [2, 3, 4] and appending 5 yields [3, 4, 5].

Add 24 regression cases against collections.deque, covering both constructors, zero/unlimited/smaller/equal/larger limits, supplied iterables, append/appendleft, cache identity, and persistence after another reopen. Negative-limit behavior and public maxlen=None assignment are unchanged; those are covered by the separate work in #383 and #369.

Validation on Linux with Python 3.12.16:

  • New regression cases: 24 passed; against the original module, 12 failed and 12 passed.
  • Full suite: DJANGO_SETTINGS_MODULE=tests.settings python -m pytest -n 2 — 275 passed, 3 Django deprecation warnings; 98.72% coverage (98% required).
  • Changed-file flake8, isort and blue checks, mypy diskcache, and git diff --check passed. Flake8 ran in a separate environment with version 7.5.0 because the older dependency is incompatible with Python 3.12.

These are local results. Other Python/OS combinations, documentation builds, and additional concurrency stress testing were not run; upstream CI results are separate.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reopening a populated Deque with maxlen does not enforce the requested bound

1 participant