Repository navigation
fix(core): refuse a key schema that names one attribute in two elements - #1576
navareamol wants to merge 5 commits into
Conversation
DynamoDB answers a key schema that names one attribute in two elements with ValidationException 'The KeySchema contains multiple key attributes with the same name', with no 'One or more parameter values were invalid:' prefix. ExtendDB answered the definition listing, the second-element sentence, or accepted the request. CreateTable checks the table's and each GSI's key schema, and an UpdateTable GSI Create checks its key schema, after the billing checks and before the key definition and key schema shape checks. CreateTable now answers its billing faults before the key schema shapes so that order holds. A schema of one HASH and one RANGE element on one name is left to its own rule. Restore from a backup skips the new check so a global secondary index that UpdateTable accepted before still restores. Refs #1509
…ave room The rule for a table key schema now runs inside validate_key_schema, after the empty, first-element and length checks and before the second-element check. The rule for each GSI runs after every key schema shape check and before the definition checks. The billing checks and the index name checks stay where main runs them. Restore tests cover both restore paths with a recorded GSI of [a HASH, b HASH, a RANGE], and the tests that pinned the moved billing order are replaced by tests that pin main's order. Refs #1509
LJMart11
left a comment
There was a problem hiding this comment.
Reviewed at 81096d0. 1 finding: 1 Docs.
The change refuses a key schema that names one attribute in two elements on CreateTable (table and GSI key schemas) and on an UpdateTable GSI Create, and keeps both restore paths on a variant of the validator that skips the new rule. Confirmed: core lib tests (1270 passed, 1 ignored) and engine lib tests (983 passed) pass under 1.94.0, both on the head and on the head merged with the current main tip; the new wire file passes 8 of 8 on SQLite; removing the UpdateTable call makes the engine test a_key_schema_naming_one_attribute_twice_is_refused_before_the_definitions_are_read fail at gsi_updates.rs:561. I sent the GSI rows [g H, g H], [a H, b H, a R], [a H, b R, a R] and the table row [pk H, pk H] (with an extra definition) to DynamoDB in us-east-1: each answered the new sentence, as the head does.
- Docs
tests/test_key_schema_repeated_attribute.py:50— Thetablerow defines onlypk, and DynamoDB answersInvalid KeySchema: Some index key attribute have no definitionfor it, not the new sentence the file's docstring says was measured.
… of messages The table row of the wire test now sends an unused second definition, which is what the service answers the new sentence for. The billing order test's failure messages no longer print the answer. Refs #1509
LJMart11
left a comment
There was a problem hiding this comment.
Checked at eee5fd8 against the list from 81096d0. 1 finding: 1 Docs. Chronology: 1 new-head delta.
The follow-up makes the wire test's table row send an unused second definition, documents why in the module docstring, and drops the answer from two assertion messages in the billing-order core test. Confirmed: the table row now matches DynamoDB (us-east-1 answered The KeySchema contains multiple key attributes with the same name for [pk HASH, pk HASH] with definitions pk, x, and the missing-definition sentence with pk alone); the two reworded assertions still fail when their billing sentence changes (each panics with its new message at key_attribute_names.rs:245 and :275); reverting either restore call to validate_create_table, or removing the CreateTable GSI loop or table-key call, fails the named tests. Core and engine lib tests pass (1270 passed, 1 ignored; 983 passed) on the head, on the head merged with main at 5826e1b, and on the head merged with #1442. The wire file passes 8 of 8 on SQLite and PostgreSQL; against DynamoDB 7 of 8 rows pass.
Previous items: 1 fixed.
- Docs
tests/test_key_schema_repeated_attribute.py:10— The new docstring says each row was measured with the definitions it sends, but DynamoDB answers the missing-definition sentence for thehash_range_on_one_of_threerow at line 92, and this file fails that row against the service.
What
CreateTable and an UpdateTable GSI
Createrefuse a key schema that names one attribute in two elements. The answer isValidationExceptionThe KeySchema contains multiple key attributes with the same name, with noOne or more parameter values were invalid:prefix.crates/core/src/validation/key_attribute_names.rs(new):validate_distinct_key_attributesand the sentence. A key schema of exactly two elements, one HASH then one RANGE, on one name is not refused here; the issue says that case has its own rule and sentence.crates/core/src/validation/mod.rs: the new check runs inside CreateTable's existing sequence. No existing check moves.crates/engine/src/gsi_updates.rs: the GSICreatebranch runs the check after the empty key schema check and before theKeys:sentence.crates/engine/src/backup.rs,crates/engine/src/backup/restore.rs: both restore paths callvalidate_recorded_table, which isvalidate_create_tablewithout the new check. Main accepts a GSI such as[a HASH, b HASH, a RANGE]through UpdateTable, so a backup of such a table has to keep restoring. The comments at both call sites say which rule is skipped.Where the check runs in CreateTable
In order, as the code runs on this branch (the new rule is marked):
length less than or equal to 2)Keys:sentence, unused definitionsThe billing checks, the index name checks and the shape checks are where main runs them. The new rule is placed before the first existing check that answers the issue's measured rows: the second-element check for a table key schema (row
[pk HASH, pk HASH]), and theKeys:definition check for a GSI key schema.Paths that take a key schema
Createvalidate_lsi_key_schemasalready requires[HASH, RANGE]with the table's HASH name, so the only shape that repeats a name is the HASH and RANGE pair left alone herehandle_restore_table_to_point_in_timeincrates/engine/src/backup_requests/pitr.rschecks the target name, the source table and the time members, then returnspitr_restore_unavailable_error()create_table_input_from_paramsincrates/engine/src/import_export/files.rsbuilds the table without callingvalidate_create_table, so import accepts a repeated name. Open issue #771 already tracks ImportTable skippingvalidate_create_table.How shapes the issue does not list are answered:
[a HASH, b HASH, a RANGE]and[a HASH, b RANGE, a RANGE](three elements) are refused by the new rule on a GSI. On a standard table key schema the length rule answers first.[a RANGE, a HASH]on a table or GSI in CreateTable gets the first-element sentence (First KeySchemaElement is not a HASH type, or the index form), because that check runs first. In an UpdateTable GSICreate, which has no shape check, it is refused with the new sentence.[a HASH, a RANGE]is not touched by the new rule and gets the same answer as on main.Why
Refs #1509.
The issue measured seven requests twice each in us-east-1 on 2026-11-25. On main they get the
Keys:sentence,Second KeySchemaElement is not a RANGE type, or pass validation. The tests use those rows and the sentence from the issue.The issue also says that on the service the rule comes after the billing checks and the definition count, and before the
Attribute Name is duplicatedcheck and the key schema shape checks. This change follows neither part of that order, so that no existing check moves: moving checks would change answers for requests the issue does not measure. The table rule runs insidevalidate_key_schemaafter the empty, first-element and length checks, and the GSI rule runs after the GSI and LSI shape and index-name checks. So[a RANGE, a HASH]on CreateTable gets the first-element sentence, not the new one. On CreateTable, a request with a billing fault and a repeated key name gets the new sentence, where the issue's order would give the billing sentence. On an UpdateTable GSICreatethe throughput-minimum check already runs first, so billing wins there, as the issue says. Every measured row in the issue still gets the issue's sentence, with the attribute definitions the wire test sends for it. One difference a reviewer measured on 2026-12-04: CreateTable with[pk HASH, pk HASH]and onlypkdefined answersInvalid KeySchema: Some index key attribute have no definitionon the service, and the new sentence only with a second definition (pk,x). Here it answers the new sentence in both cases, because the table rule runs before the definition checks. The wire test'stablerow now sendspk,x. The same holds for an UpdateTable GSICreateof[a HASH, b HASH, a RANGE]on a table keyedpk: with definitionsa,bthe service answers the missing-definition sentence, and withpk,a,bthe new sentence (measured by a reviewer on 2026-12-04). Here both get the new sentence, becausegsi_updates.rsruns the rule before the definition check. The wire test'shash_range_on_one_of_threerow now sendspk,a,b.Testing done
Branch
fix/1509-duplicate-key-attribute, three commits on main atc05766036. Run on the dev desktop. The desktop tree and the Mac tree are both2ba543d81. Mergingorigin/main(5826e1beaat the time of writing) withgit merge-treehas no conflicts.cargo fmt --checkcargo +1.97.0 clippy -p extenddb-core -p extenddb-engine --all-targets -- -D warningsgsi_updates, 1 engine restore), run 20 times; the wholegsi_updatesmodule (11 tests) ran with themtests/test_key_schema_repeated_attribute.py(8 cases), SQLite, 3 runsef5aff64a) before the check movedNew tests: the core tests for the rows and for main's order (length and first-element rules, the index name and GSI shape faults, GSI and table billing faults); the engine test for the UpdateTable rows and the reversed pair; and
a_backup_whose_gsi_names_an_attribute_twice_restores_on_both_paths, which runs the legacy path (backup.rs) and the manifest path (backup/restore.rs) on a recorded GSI[a HASH, b HASH, a RANGE], requires both to accept it and to agree, and checks CreateTable refuses the same input.Controls, each on the committed tree, reverted with
git checkout -- crates, tree clean after each:if true { return Ok(()); }at the top ofvalidate_distinct_key_attributesa_key_schema_naming_one_attribute_twice_is_refused_before_the_definitions_are_readand the restore testgsi_updates.rsa_key_schema_naming_one_attribute_twice_is_refused_before_the_definitions_are_readvalidate_recorded_tablepassestruea_recorded_table_with_a_repeated_gsi_key_attribute_still_passes; engine restore testvalidate_create_table_witha_gsi_key_schema_naming_one_attribute_twice_gets_the_sentence,a_recorded_table_with_a_repeated_gsi_key_attribute_still_passes,the_billing_checks_keep_their_place_after_the_key_schema_checks; engine restore testvalidate_key_schemaa_table_key_schema_naming_pk_twice_gets_the_sentence,the_sentence_comes_before_the_key_definition_and_shape_checksbackup.rscall revertedvalidate_create_tablein place ofvalidate_recorded_tablebackup/restore.rscall revertedNot run: main's lib test counts, Cassandra and MongoDB on this head, any request against the live service.
To rerun the wire file: build
cargo build -p extenddb --no-default-features --features sqlite, runextenddb initandserve, provision credentials withdevtools/provision-test-credentials, setEXTENDDB_TEST_ENDPOINTand runpytest tests/test_key_schema_repeated_attribute.py.Open question
None of these orders is measured on the service. Has anyone measured them?
[pk HASH, pk HASH, pk RANGE]on a standard table (the length rule answers first here, as on main).[a RANGE, a HASH]and[a HASH, b RANGE, a RANGE], and a repeated name in an LSI.#595 changes the same four files (
crates/core/src/validation/mod.rs,crates/engine/src/gsi_updates.rs,crates/engine/src/backup.rs,crates/engine/src/backup/restore.rs). It defines its ownvalidate_recorded_tableand its own order of these checks (index names, billing, then the key definition rules), and does not contain this sentence. The two will conflict. Whichever lands second should rebase; this rule goes before #595's duplicate definition rule. Question for #595's author: which order did you measure for index names, billing and the key schema shapes?