Skip to content

fix(engine): answer TransactGetItems {"Item": {}} for an item its projection leaves empty - #1571

Closed
hitesh96db wants to merge 2 commits into
mainfrom
fix/867-transact-get-empty-item
Closed

hitesh96db wants to merge 2 commits into
mainfrom
fix/867-transact-get-empty-item

Conversation

@hitesh96db

Copy link
Copy Markdown
Contributor

What

TransactGetItems now answers {"Item": {}} for an existing item whose ProjectionExpression selects no attribute (a name the item lacks, or a.b where a is a number). A missing item still answers {}. In crates/engine/src/transact_get_items.rs the projected item was filtered out when empty, which made it look like a missing item. The filter is dropped.

One exception is kept: a list index past the end of the list (l[7]) still answers {}, as the issue measured on DynamoDB. Projection::reaches_past_list_end in crates/core/src/expression/projection.rs detects that case. The issue asks for that case to be measured again; I did not call DynamoDB, so it follows the issue's measurement and should be re-measured before merge. If DynamoDB answers {"Item": {}} there, delete the helper and its call.

The change is in the engine, so it applies to every backend. GetItem and BatchGetItem already return the empty item.

Open PR #826 touches TransactGetItems validation. This PR edits only the response-building step at the end of the handler, so a conflict should be small.

Why

Fixes #867. A client cannot tell an existing item from a missing one.

Testing done

  • cargo test -p extenddb-core --lib projection: 38 passed, including the new reaches_past_list_end_only_for_a_missing_list_element.
  • cargo test -p extenddb-engine --lib transact: 28 passed.
  • New test_transact_get_projection_selecting_nothing in tests/python/test_transactions.py (nonexistent attribute, path into a number, l[7], missing item), run on the SQLite backend: 6 transact_get tests passed. The pre-fix failure was not run on a build; by reading, the removed filter made the first two cases answer {}.
  • cargo fmt --all -- --check and cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine --lib -- -D warnings clean. --all-targets fails on an unused variable in crates/core/tests/data_file_decode_peak.rs, which is present on main.
  • Not run: PostgreSQL, MongoDB, Cassandra (the fix is backend independent).

Upgrade manual: v1.2.0: entry added.

Checklist

  • Conventional-commit title
  • DCO sign-off
  • Tests added
  • Upgrade manual entry

…jection leaves empty

Fixes #867.

Signed-off-by: Hitesh Sharma <hts@amazon.com>

@LJMart11 LJMart11 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 2d7d06b. 1 finding: 1 Important.

The change makes TransactGetItems answer {"Item": {}} for an existing item whose projection selects nothing, keeping {} for a missing item and for a list index past the end. Confirmed: cargo test -p extenddb-core -p extenddb-engine --lib passes (1261 and 981 tests) on the head and on the head merged with the current origin/main; the new Python test passes on SQLite (6 transact_get tests); putting the base's filter back, and forcing the past-list-end helper to false, each fail that test (at the first assertion and at the l[7] assertion respectively).

  • Important crates/engine/src/transact_get_items.rs:183 — Live DynamoDB answered {} (not {"Item": {}}) for an existing item with projection nope or n.b, so this change moves ExtendDB away from the service.

// An existing item whose projection selects nothing is
// `{"Item": {}}`, not the missing-item `{}`. Measured exception:
// an index past the end of a list answers `{}` (issue #867).
Some(p) => opt

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important
The change at transact_get_items.rs:183-187 answers {"Item": {}} for an existing item whose projection selects nothing, on the premise (issue #867) that DynamoDB does so. Measured on 2026-12-03 in us-east-1, DynamoDB's raw response body for TransactGetItems on an existing item was {"Responses":[{}]} for nope, n.b (n a number), l[7], l[0].x, m.zz and l[0][1]; l[0] and l[7],n returned the selected attributes. A missing key with no projection also gave {"Responses":[{}]}. GetItem on the same item answered {"Item":{}} for all of those. So DynamoDB's TransactGetItems does not distinguish them today, and the head now answers {"Item": {}} for nope, n.b on ExtendDB (new test passes on SQLite) where main and the service answer {}. A client that relied on {} for an empty projection (as the service gives it) now sees a different entry, and the upgrade-manual entry at docs/manuals/07-upgrade-manual.md:428 documents the new behavior as if it matched the service.

Fix: re-measure the issue's 2026-11-05 result; if the service now answers {}, revert the change (the reaches_past_list_end helper, projection.rs:102-125, then has no use) or record the divergence in docs/differences-from-dynamodb.md; tests/python/test_transactions.py:261-287 (expects {"Item": {}} for nope and n.b) and the manual entry change with it; the test also fails against the live service (first assertion, nope) when run through the live wrapper, which the issue asked for ("against both targets"). No migration.

Evidence: aws dynamodb transact-get-items --debug with Key pk=k1, ProjectionExpression nope printed b'{"Responses":[{}]}'; extenddb-live-ddb-pytest tests/python/test_transactions.py -k projection_selecting_nothing failed at assert get("k1", "nope") == {"Item": {}}. The behavior may have changed since the issue's measurement; the PR body says it did not call DynamoDB.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, thanks. Your raw-body measurement (2026-12-03, us-east-1) shows TransactGetItems answering {"Responses":[{}]} for an existing item whose projection selects nothing (nope, n.b, l[7], l[0].x, m.zz, l[0][1]), the same as a missing item, and the new test fails against the live service. That is what main already answers, and main's test_transact_get_empty_projection_omits_item has asserted it since May; cf73b0e flipped that test to follow #867, which was wrong. Closing this PR without merging; #867 will be closed as not reproducible with your measurement.

…ects nothing

test_transact_get_empty_projection_omits_item asserted that the response entry has no Item, the answer this change fixes. DynamoDB answers {"Item": {}} for an existing item whose projection resolves to no attribute (measured 2026-11-05, #867).

Signed-off-by: Hitesh Sharma <hts@amazon.com>
@hitesh96db

Copy link
Copy Markdown
Contributor Author

Closing without merging. LJMart11 measured DynamoDB on 2026-12-03 (raw response body, us-east-1): TransactGetItems answers {} for an existing item whose projection selects nothing, the same as for a missing item, and the new test fails against the live service. main already answers this way, so the change would move ExtendDB away from the service. See #1571 (comment). #867 is closed as not reproducible.

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.

TransactGetItems answers {} for an item its projection leaves empty

2 participants