Skip to content

fix(query): requests of growing reads ask for at most a page's worth of items - #70

Merged
kalaspuff merged 3 commits into
fixes-stack/08-enum-valuesfrom
fixes-stack/09-bounded-limits
Oct 30, 2026
Merged

kalaspuff merged 3 commits into
fixes-stack/08-enum-valuesfrom
fixes-stack/09-bounded-limits

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Since 0.3.0, a read with a limit asks DynamoDB for only as many items as it still needs. When dynamoxy's own filters remove items from a page, the next request asks for four times as many, so that a few requests find what the limit wants. Those filters are the entity type of single-table models and the guard items of unique models, plus the client check of a templated sort key prefix that where() replaced. The growth had no bound: after about 16 such pages in a row, the request's Limit no longer fit DynamoDB's (and the binding's) unsigned 32-bit integer, and the read raised OverflowError: number too large to fit in target type.

The review that found it reproduced it with 12,000 customers of about 1 KB and no orders in a shared table: client.model(Order).scan().exists() raised OverflowError after 17 requests asking for 1, 4, 16, … 4,294,967,296 items. first(), exists(), limit(n) and the iteration of such reads were affected, and so was limit(n) with any n above 2³².

Every request now asks for at most 1,048,576 items: growing reads, page(), and a limit() or page_size() above that. That is more than a 1 MB page can hold, so the 1 MB page size bounds them as before, and the reads still need only a few requests.

Verified with a new integration test on the in-memory backend and MiniStack. It raises the growth factor, so that the second request already exceeds 2³², and reads with limit(2**33) and page_size(2**33) through page() and iteration: before the fix both backends raised OverflowError. Also with the whole suite, ruff, pyrefly and the consistency checks.

Checklist

  • Tests cover the change (in-memory backend and MiniStack)
  • Docs updated (changelog; no guide documents the growth)
  • make check passes locally (lint, types, consistency, tests; no Rust change)
  • Breaking change? No

fctl session


Note

Low risk. It only caps the Limit that query and scan requests send, in one Python module, and the cap is above what a 1 MB page can hold, so results are unchanged.

What it does. Reads with a limit grew the Limit of their next request fourfold whenever dynamoxy's own filters (entity type, unique guards, the client check of a templated sort key prefix) removed items from a page. The growth had no bound, so after about 16 such pages the number no longer fit an unsigned 32-bit integer and the read raised OverflowError. Every request now asks for at most 1,048,576 items, applied where the request parameters are built, so growing reads, page(), and a limit() or page_size() above that bound are all covered. A new integration test covers it on the in-memory backend and MiniStack, and the changelog gets an entry.

fctl review's first look at 125f537 · 3 files, +51 −3 · Review agent settings

@fctl-sh

fctl-sh Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Stack of 5 open pull requests (from a pass over the library for bugs; #61 to #65 are merged already), merged in this order with "Squash and merge":

  1. fix(client): writes whose retries run out after an uncertain attempt are unknown #67 fix(client): writes whose retries run out after an uncertain attempt are unknown
  2. fix(repository): items stored before the model had a version can be saved #68 fix(repository): items stored before the model had a version can be saved
  3. fix(models): members of mixin enums are the plain values of str and int fields #69 fix(models): members of mixin enums are the plain values of str and int fields
  4. fix(query): requests of growing reads ask for at most a page's worth of items #70 fix(query): requests of growing reads ask for at most a page's worth of items ← this pull request
  5. fix(errors): errors pickle, so they cross process boundaries #72 fix(errors): errors pickle, so they cross process boundaries

The findings that are not fixed here are filed as issues (see the next comment on #72).

@fctl-review

This comment has been minimized.

Comment thread python/dynamoxy/query.py Resolved
…of items

When dynamoxy's own filters (the entity type, guard items) or client
checks (a templated sort key prefix that where() replaced) removed items
from a page, the next request asked for four times as many, without a
bound. After about 16 such pages in a row (16 MB of other entities in a
shared table), the Limit no longer fit the request's unsigned 32-bit
integer, and first(), exists(), limit() and iteration raised
OverflowError. `limit(n)` with n above that raised it at once.

Requests now ask for at most 1,048,576 items, more than a 1 MB page
can hold, so the page size bounds them as before.

Co-authored-by: Carl Oscar Aaro <[email protected]>
@kalaspuff
kalaspuff force-pushed the fixes-stack/09-bounded-limits branch from e4ce09d to 7e5e463 Compare October 30, 2026 21:40
fctl-sh Bot and others added 2 commits October 30, 2026 21:42
…orth too

The bound of the request Limit only applied while growing reads
iterated: `query.limit(2**33).page()` and `page_size(2**33)` still sent
a Limit that the request cannot hold and raised OverflowError. The bound
now applies where every request is built.

Co-authored-by: Carl Oscar Aaro <[email protected]>
This was referenced Oct 30, 2026
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