Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/engine/src/update_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ pub async fn handle_update_item(
ReturnValues::None => None,
ReturnValues::AllOld => old_item,
ReturnValues::AllNew => new_item,
ReturnValues::UpdatedOld => {
old_item.map(|item| filter_to_updated_attrs(&item, &actions, &maps))
}
ReturnValues::UpdatedNew => {
new_item.map(|item| filter_to_updated_attrs(&item, &actions, &maps))
}
ReturnValues::UpdatedOld => old_item
.map(|item| filter_to_updated_attrs(&item, &actions, &maps))
.filter(|item| !item.is_empty()),
ReturnValues::UpdatedNew => new_item
.map(|item| filter_to_updated_attrs(&item, &actions, &maps))
.filter(|item| !item.is_empty()),
};

let output = UpdateItemOutput {
Expand Down
47 changes: 47 additions & 0 deletions tests/test_item_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,53 @@ def test_update_item_ne_comparison_missing_attribute(self, dynamodb_client, upd_
resp = dynamodb_client.get_item(TableName=upd_table, Key={"pk": {"S": "ne-missing"}})
assert resp["Item"]["data"]["S"] == "ok"

def test_update_item_remove_with_updated_new_omits_attributes(self, dynamodb_client, upd_table):
"""REMOVE leaves nothing in UPDATED_NEW: Attributes field must be omitted, not returned as {}."""
dynamodb_client.put_item(
TableName=upd_table,
Item={"pk": {"S": "remove-empty"}, "map_attr": {"M": {"child": {"S": "old"}}}},
)
resp = dynamodb_client.update_item(
TableName=upd_table,
Key={"pk": {"S": "remove-empty"}},
UpdateExpression="REMOVE map_attr",
ReturnValues="UPDATED_NEW",
)
assert "Attributes" not in resp, f"expected Attributes omitted, got {resp.get('Attributes')!r}"

def test_update_item_set_new_attribute_with_updated_old_omits_attributes(
self, dynamodb_client, upd_table
):
"""SET on a brand-new attribute has no prior value: UPDATED_OLD must omit Attributes."""
dynamodb_client.put_item(
TableName=upd_table,
Item={"pk": {"S": "set-new-old"}},
)
resp = dynamodb_client.update_item(
TableName=upd_table,
Key={"pk": {"S": "set-new-old"}},
UpdateExpression="SET fresh_attr = :v",
ExpressionAttributeValues={":v": {"S": "new"}},
ReturnValues="UPDATED_OLD",
)
assert "Attributes" not in resp, f"expected Attributes omitted, got {resp.get('Attributes')!r}"

def test_update_item_legacy_delete_with_updated_new_omits_attributes(
self, dynamodb_client, upd_table
):
"""Legacy AttributeUpdates DELETE on a Map mirrors REMOVE: UPDATED_NEW must omit Attributes."""
dynamodb_client.put_item(
TableName=upd_table,
Item={"pk": {"S": "legacy-delete"}, "map_attr": {"M": {"child": {"S": "old"}}}},
)
resp = dynamodb_client.update_item(
TableName=upd_table,
Key={"pk": {"S": "legacy-delete"}},
AttributeUpdates={"map_attr": {"Action": "DELETE"}},
ReturnValues="UPDATED_NEW",
)
assert "Attributes" not in resp, f"expected Attributes omitted, got {resp.get('Attributes')!r}"


# ---------------------------------------------------------------------------
# DeleteItem tests
Expand Down
Loading