Skip to content

Fix query indexing at the cache boundary - #869

Open
fallintoplace wants to merge 1 commit into
redis:mainfrom
fallintoplace:fix/query-cache-boundary
Open

fallintoplace wants to merge 1 commit into
redis:mainfrom
fallintoplace:fix/query-cache-boundary

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Oct 4, 2026 •

Copy link
Copy Markdown

What

  • Fix query indexing at the cache boundary.

Why

  • With one cached result, get_item(1) could raise IndexError while more results exist.

Implementation

  • Use a strict bounds check in both accessors.
  • Cover cached, uncached, and out-of-range indexes in async and sync queries.

Note

Low Risk
Small bounds-check change in query indexing with targeted tests; behavior fix for partial caches, no auth or data-model changes.

Overview
Fixes off-by-one cache hits when indexing a FindQuery that only has a partial result set loaded (e.g. after execute(exhaust_results=False)).

Both sync __getitem__ and async get_item now treat the cache as usable only when len(_model_cache) > item instead of >= item. With a single cached row, index 1 no longer reads past the cache and raises IndexError; it clones the query with offset=1, limit=1 and fetches the next document.

Adds tests/test_find_query_cache.py to cover cached vs uncached indexes and out-of-range access for async get_item and sync [].

Reviewed by Cursor Bugbot for commit 2e2d779. Bugbot is set up for automated code reviews on this repo. Configure here.

This branch has not been deployed

No deployments
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.

1 participant