Repository navigation
fix(engine): refuse a BatchGetItem table value with no Keys by path - #1301
LeeroyHannigan wants to merge 5 commits into
Conversation
A BatchGetItem table value of {} or {"Keys": null} within the table
count got a SerializationException with the parser's text. DynamoDB
answers a ValidationException that names each such table at
requestItems.<table>.member.keys. It lists the tables in one message,
in table name order. It still answers a SerializationException when
another member of the value has another JSON type. These answers were
measured on 20 and 21 Nov 2026.
KeysAndAttributes now reads Keys as an optional list. The handler
refuses a table value without one after the count checks and before
it reads any table. A request over the table count keeps its answer.
Fixes #1283.
demohan
left a comment
There was a problem hiding this comment.
A BatchGetItem table value with no Keys is refused by member path at 2af9d1f, and no shape answers worse than on the base. Of 38 shapes sent twice to us-east-1 and to this head and its base on SQLite and PostgreSQL, this head matches the service's text on 17, its clause set on 3 more and its error type on 15, and the two backends agree everywhere; the ten-clause cap matches the service's 10 clauses for 11 tables. Removing the null refusal or the sort fails the tests, fmt, clippy, the 1.91.1 check and the core and engine lib tests are clean, and test_batch.py, test_batch_operations.py and test_authz_cross_account.py pass on both backends. Onto main at 222d80a the head merges cleanly and builds and passes the 1.94.0 check; the wasm parity failure is #1215's BatchWriteItem count form. No merged PR fixes #1283.
The branch conflicts with its base: it was cut from 248c7ea, and the base has since merged main (5252eda) and taken 98d471c, which adds validation_refusal in the lines refusal() rewrites here, so the green CI ran on a tree without them. Merging the base and calling validation_refusal would resolve it.
I will approve once the base is merged, the missing-Keys tables are not asserted in name order, and a table with no Keys beside a count fault answers as the service does.
| .iter() | ||
| .filter_map(|&(table, keys)| keys.is_none().then_some(table)) | ||
| .collect(); | ||
| missing.sort_unstable(); |
There was a problem hiding this comment.
The service does not list the missing-Keys tables in name order: over 16 random prefixes and 5 rows, name order held in 31 of 80 sends, a repeat of the same names gave the same order 40 of 40, and the written order made no difference (16 of 16). Run against the service, the new two-target test failed 2 of 10 and then 3 of 10 at its endswith order check (test_batch.py:445 and :487, and the unit row at line 596). Accepting any order in the tests, and saying so in the comment and the body, would hold what the service does.
There was a problem hiding this comment.
d7c260b changes the check. Against DynamoDB, the wire test checks the count, and that each clause is one of the expected clauses, in any order. Against ExtendDB it compares the message, with the tables in name order. The doc of check_batch_get, the test comments and the body say that DynamoDB uses an order of its own, and the unit rows are ExtendDB's order. DynamoDB's order matches #781's hash_map_order on all 7 measured requests with more than one null clause, of 25 November and 2 December.
| .iter() | ||
| .map(|(table, ka)| (table.as_str(), ka.keys.as_ref().map(Vec::len))) | ||
| .collect(); | ||
| check_batch_counts("BatchGetItem", &tables)?; |
There was a problem hiding this comment.
With a per-table count fault or an over-total request beside a table with no Keys, the counts answer alone here. For {a: {"Keys": []}, b: {}} the service sends two clauses, the null clause for b and Value '[]' at 'requestItems.<a>.member.keys'; for 101 keys and {}, two clauses; for 60 and 50 keys and {}, the null clause alone, where this head sends Too many items requested. The base answers the same as this head. Removing the cap at line 146, or moving the null check ahead of the counts, still passes all 872 engine tests, so neither is pinned.
There was a problem hiding this comment.
I measured four of these again on 2 December. A table {} went beside {"Keys": []}, beside a table of 101 keys, beside tables of 60 and 41 keys, and into a request of 101 tables. DynamoDB gave the answers you list, both sends. On #1285 and on main the count checks run before the null check. The server's check before authorization does the same, so this PR keeps that order. #1300 tracks it, with these four requests added.
d7c260b pins the cap and the order. A row of 11 tables fails without the cap in validation_refusal, and two rows fail with the null check before the counts.
| .collect(); | ||
| request_limits::check_batch_counts("BatchGetItem", &counts)?; | ||
| // table. The server runs the same checks before authorization. Then | ||
| // refuse a table value with no Keys list, so every table below has one. |
There was a problem hiding this comment.
The null check runs after authorization: a user with no policy gets AccessDeniedException for {} here and on the base, while Keys: [] gets the ValidationException before authorization. On the service the null and count clauses come in one message, so they are likely one pass before authorization; that is inferred, since it needs a restricted principal to measure. The module doc's "return the same text" no longer holds. request_limits.rs is now 637 lines.
There was a problem hiding this comment.
The null check stays in the handler. DynamoDB's answer to a principal with no policy is not measured, so the order around authorization is open, as you say. d7c260b changes the module doc: both paths give the same count refusal, and only the handler refuses a table with no Keys, after authorization. request_limits.rs has 877 lines at this head.
This branch was cut from 248c7ea. The base now holds main at 01556cf and the quoted request map form of the BatchWriteItem count refusals. It also finds a batch value of another JSON type in any table. The base added validation_refusal in the lines that refusal() rewrote here, and it has no count_error now. The merge drops refusal() and count_error. check_batch_get calls validation_refusal, which keeps the first 10 clauses, so its own cap goes.
NOT_NULL moves from partiql/request_checks.rs to request_limits.rs, beside AT_LEAST_ONE, as #1375 moved that constant. check_batch_get writes its null clause with it. The PartiQL module builds only with the partiql feature, and check_batch_get runs in every build, so the clause cannot come from Found::null.
DynamoDB gave the tables with no Keys one order on both sends, but not name order (measured 25 Nov and 2 Dec 2026). check_batch_get keeps the name order, and its doc and the test comments now say so. The wire test checks the clauses in any order against DynamoDB, and the message by equality against ExtendDB. A new row of 11 tables with no Keys expects the first 10 in name order. Its wire row checks that DynamoDB names 10 of the 11. Two unit rows pin ExtendDB's answer to a table with no Keys beside a count fault. There DynamoDB adds the null clause, or answers it alone (#1300). The module doc says that the null refusal comes after authorization. The handler comment says that the reads of keys never take their default.
|
Changes since the last review
validation_refusalin the lines thatrefusal()rewrote, and droppedcount_error. The merge dropsrefusal()andcount_error, andcheck_batch_getcallsvalidation_refusal, which keeps the first 10 clauses.NOT_NULLfrompartiql/request_checks.rstorequest_limits.rs, besideAT_LEAST_ONE.check_batch_getwrites its null clause with it.check_batch_get, the module doc and the handler comment now say what the code does.What
Within the table and key counts, a BatchGetItem table value of
{}or{"Keys": null}now gets DynamoDB's ValidationException at the member path ofKeys:Value null at 'requestItems.<t>.member.keys' failed to satisfy constraint: Member must not be null. Before, it got a SerializationException with the parser's text.KeysAndAttributesincrates/core/src/types/batch.rsreadsKeysas an optional list.check_batch_getincrates/engine/src/request_limits.rsruns the count checks, then refuses each table value with noKeys, in one message of at most 10 clauses throughvalidation_refusal. It lists the tables in name order. DynamoDB lists the same clauses in an order of its own. The same names got the same order on each send, and that order was neither the name order nor the order of the request. The handler runscheck_batch_getafter authorization, before it reads any table.The null clause uses
NOT_NULL, which moves from the PartiQL request checks torequest_limits.rs.Found::nullin the PartiQL checks writes the same clause, but it builds only with thepartiqlfeature, and this check runs in every build.The base of this PR is #1285.
Fixes #1283
Why
These are DynamoDB's answers in us-east-1 on table names that do not exist, measured on 20, 21 and 25 November and 2 December 2026. Each request went out twice and got the same answer both times. KEYS is
{"Keys": [{"pk": {"S": "a"}}]}. NULL(t) is the clause above for the tablet. SE is SerializationException.RequestItems{}or{"Keys": null}{}or{"ProjectionExpression": "pk"}{}2 validation errors detected:and NULL of each{}, KEYS and{"Keys": null}, in two written orders2 validation errors detected:, NULL of the first and the third, in an order of its own...-zz,...-aand...-mmm, each{}3 validation errors detected:, NULL ofzz,mmmanda{}10 validation errors detected:, NULL of 10 of the 11 tables{"Keys": null}with"ConsistentRead": "x"or"ProjectionExpression": 5{"Keys": []}Value at 'RequestItems.<t>.member.Keys' failed to satisfy constraint: Member must have length greater than or equal to 1{}, and"ReturnConsumedCapacity": "X"returnConsumedCapacitya*with{}a*)requestItemsWith this change, 11 of the 14 measured requests get DynamoDB's clauses, against 3 on #1285. The request of 11 tables gets 10 clauses too, for other tables than DynamoDB's 10. For an SE these counts compare the type only, because its texts are #1012.
This change gives a new answer to a request that is not measured. A table with no
Keyscan sort before a table whose parse gives another ValidationException, such as an emptyExpressionAttributeNames. That request now gets the other text, where #1285 answered SerializationException (#1300). On a MongoDB build the parse reads the tables in the written order, so there the written order decides which fault comes first.A principal with no policy gets AccessDeniedException for a table without
Keys, on #1285 and with this PR. DynamoDB's answer to that principal is not measured, because it needs a principal with no policy.Testing done
At ce056e8, whose tree is the tree of d7c260b:
cargo test -p extenddb-core --lib: 1242 passed.cargo test -p extenddb-engine --lib: 980 passed.cargo test -p extenddb-wasm-adapter: 4 passed, theparitycorpus test among them.cargo +1.97.0 fmt --all -- --check, the two clippy commands of.github/workflows/clippy.ymlwith-D warningsonextenddb-core,extenddb-engineandextenddb-server,cargo +1.97.0 clippy -p extenddb-engine --lib --no-default-features -- -D warningsandcargo +1.94.0 check --all-targetson the same crates are clean.python3 -m pytest --collect-only -qcollects 7223 tests intestsand 742 intests/python, with no error.batch_get_tables_without_keyshas 12 rows. Without the cap invalidation_refusal, row 9 fails. Without the sort, rows 5 and 9 fail. With the null check before the counts, rows 10 and 11 fail.tests/python/test_batch.py,tests/test_batch_operations.pyandtests/test_batch_write_validation_order.pypassed 122 tests on SQLite and 122 on PostgreSQL, 77 of them intest_batch.py. On SQLite,tests/test_partiql_requests.py,tests/test_partiql_batch.pyandtests/test_partiql_transaction.pypassed 439 tests, with 2 expected failures. On SQLite,tests/test_authz_cross_account.pypassed 19.test_batch.pyagainst a server built from fix(engine): refuse a batch table value of another type before counts #1285's head: 9 failed and 68 passed. The 9 failures are the rows that expect a null clause.Line counts against #1285: production +66 -23, tests +154 -0.
This PR adds conflicts in
crates/engine/src/batch_get_item.rswith #507 and #536, and with #547, #549, #557 and #587, which stack on #536. The loops overKeyschange in each. #536 also builds aKeysAndAttributes, which needskeys: Some(...)after this PR.Not in this PR:
Keys(BatchGetItem: a table with no Keys beside another fault gets one clause, where DynamoDB lists the null clause and the other fault #1300).Keysbeside a count fault. There DynamoDB lists the null clause with the count clauses, in a quoted, lower case form. It answers the null clause before the key total. ExtendDB answers the count fault alone, as on fix(engine): refuse a batch table value of another type before counts #1285 and main, because the count checks run first (BatchGetItem: a table with no Keys beside another fault gets one clause, where DynamoDB lists the null clause and the other fault #1300).hash_map_order(crates/core/src/map_order.rson its branch) gives that order for the 7 measured requests with more than one null clause, and the same 10 of 11 tables.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, or public CLI surface, an RFC has been accepted or is linked
below. Otherwise, an ADR captures the decision (link below).
ADR / RFC: n/a
Breaking changes
A BatchGetItem table value with no
Keysgets a ValidationException in place of a SerializationException, as the What section says. Other requests get the same answers as before.By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.