Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(dynamodb): validate legacy Expected operands without rejecting Value (#5508)

Andre Kurait255ad9616882
diff --git a/compatibility-tests/sdk-test-python/tests/fixtures/dynamodb-legacy-expected-aws.json b/compatibility-tests/sdk-test-python/tests/fixtures/dynamodb-legacy-expected-aws.json
new file mode 100644
index 0000000000..b461bbb142
--- /dev/null
+++ b/compatibility-tests/sdk-test-python/tests/fixtures/dynamodb-legacy-expected-aws.json
@@ -0,0 +1,77 @@
+{
+ "metadata": {"region": "us-east-1", "source": "Live AWS API observations; response codes/messages transcribed, not inferred from documentation.", "original_pairs_rechecked_utc": "2026-10-12T17:30:07.623461Z", "operands_update_observed_utc": ["2026-10-12T17:31:04.898090Z", "2026-10-12T17:31:24.548721Z"], "operands_put_delete_completed_utc": "2026-10-12T17:32:13.120823Z", "operand_operations": ["PutItem", "UpdateItem", "DeleteItem"], "operand_seed": {"tested": {"S": "READY"}, "marker": {"S": "before"}}, "cleanup": "Temporary tables deleted after testing."},
+ "operand_cases": [
+ {"label": "EQ-missing", "condition": {"ComparisonOperator": "EQ"}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Value or AttributeValueList must be used with ComparisonOperator: EQ for Attribute: tested"},
+ {"label": "NE-missing", "condition": {"ComparisonOperator": "NE"}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Value or AttributeValueList must be used with ComparisonOperator: NE for Attribute: tested"},
+ {"label": "LE-missing", "condition": {"ComparisonOperator": "LE"}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Value or AttributeValueList must be used with ComparisonOperator: LE for Attribute: tested"},
+ {"label": "LT-missing", "condition": {"ComparisonOperator": "LT"}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Value or AttributeValueList must be used with ComparisonOperator: LT for Attribute: tested"},
+ {"label": "GE-missing", "condition": {"ComparisonOperator": "GE"}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Value or AttributeValueList must be used with ComparisonOperator: GE for Attribute: tested"},
+ {"label": "GT-missing", "condition": {"ComparisonOperator": "GT"}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Value or AttributeValueList must be used with ComparisonOperator: GT for Attribute: tested"},
+ {"label": "CONTAINS-missing", "condition": {"ComparisonOperator": "CONTAINS"}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Value or AttributeValueList must be used with ComparisonOperator: CONTAINS for Attribute: tested"},
+ {"label": "NOT_CONTAINS-missing", "condition": {"ComparisonOperator": "NOT_CONTAINS"}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Value or AttributeValueList must be used with ComparisonOperator: NOT_CONTAINS for Attribute: tested"},
+ {"label": "BEGINS_WITH-missing", "condition": {"ComparisonOperator": "BEGINS_WITH"}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Value or AttributeValueList must be used with ComparisonOperator: BEGINS_WITH for Attribute: tested"},
+ {"label": "IN-missing", "condition": {"ComparisonOperator": "IN"}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Value or AttributeValueList must be used with ComparisonOperator: IN for Attribute: tested"},
+ {"label": "BETWEEN-missing", "condition": {"ComparisonOperator": "BETWEEN"}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Value or AttributeValueList must be used with ComparisonOperator: BETWEEN for Attribute: tested"},
+ {"label": "NULL-missing", "condition": {"ComparisonOperator": "NULL"}, "status": "ConditionalCheckFailedException", "message": "The conditional request failed"},
+ {"label": "NULL-empty", "condition": {"ComparisonOperator": "NULL", "AttributeValueList": []}, "status": "ConditionalCheckFailedException", "message": "The conditional request failed"},
+ {"label": "NOT_NULL-missing", "condition": {"ComparisonOperator": "NOT_NULL"}, "status": "success", "message": null},
+ {"label": "NOT_NULL-empty", "condition": {"ComparisonOperator": "NOT_NULL", "AttributeValueList": []}, "status": "success", "message": null},
+ {"label": "eq-empty", "condition": {"ComparisonOperator": "EQ", "AttributeValueList": []}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Invalid number of argument(s) for the EQ ComparisonOperator"},
+ {"label": "ne-two", "condition": {"ComparisonOperator": "NE", "AttributeValueList": [{"S": "READY"}, {"S": "OTHER"}]}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Invalid number of argument(s) for the NE ComparisonOperator"},
+ {"label": "eq-two", "condition": {"ComparisonOperator": "EQ", "AttributeValueList": [{"S": "READY"}, {"S": "OTHER"}]}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Invalid number of argument(s) for the EQ ComparisonOperator"},
+ {"label": "eq-both-empty", "condition": {"ComparisonOperator": "EQ", "Value": {"S": "READY"}, "AttributeValueList": []}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Value and AttributeValueList cannot be used together for Attribute: tested"},
+ {"label": "eq-both-conflicting", "condition": {"ComparisonOperator": "EQ", "Value": {"S": "OTHER"}, "AttributeValueList": [{"S": "READY"}]}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Value and AttributeValueList cannot be used together for Attribute: tested"},
+ {"label": "NULL-value", "condition": {"ComparisonOperator": "NULL", "Value": {"S": "READY"}}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Invalid number of argument(s) for the NULL ComparisonOperator"},
+ {"label": "NOT_NULL-value", "condition": {"ComparisonOperator": "NOT_NULL", "Value": {"S": "READY"}}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Invalid number of argument(s) for the NOT_NULL ComparisonOperator"},
+ {"label": "BETWEEN-value", "condition": {"ComparisonOperator": "BETWEEN", "Value": {"S": "READY"}}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Invalid number of argument(s) for the BETWEEN ComparisonOperator"},
+ {"label": "NULL-list", "condition": {"ComparisonOperator": "NULL", "AttributeValueList": [{"S": "READY"}]}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Invalid number of argument(s) for the NULL ComparisonOperator"},
+ {"label": "IN-empty", "condition": {"ComparisonOperator": "IN", "AttributeValueList": []}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Invalid number of argument(s) for the IN ComparisonOperator"},
+ {"label": "invalid-operator", "condition": {"ComparisonOperator": "BOGUS", "Value": {"S": "READY"}}, "status": "ValidationException", "message": "1 validation error detected: One or more parameter values were invalid: Invalid comparison operator"},
+ {"label": "eq-value", "condition": {"ComparisonOperator": "EQ", "Value": {"S": "READY"}}, "status": "success", "message": null},
+ {"label": "ne-value", "condition": {"ComparisonOperator": "NE", "Value": {"S": "OTHER"}}, "status": "success", "message": null},
+ {"label": "IN-value", "condition": {"ComparisonOperator": "IN", "Value": {"S": "READY"}}, "status": "success", "message": null},
+ {"label": "BETWEEN-list", "condition": {"ComparisonOperator": "BETWEEN", "AttributeValueList": [{"S": "A"}, {"S": "Z"}]}, "status": "success", "message": null}
+ ],
+ "valid_pairs": [
+ {"name": "S-EQ-equal", "operation": "update_item", "seed": {"tested": {"S": "READY"}}, "conditions": {"tested": ["EQ", {"S": "READY"}]}, "aws_status": "success"},
+ {"name": "S-EQ-unequal", "operation": "update_item", "seed": {"tested": {"S": "PENDING"}}, "conditions": {"tested": ["EQ", {"S": "READY"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "S-EQ-missing", "operation": "update_item", "seed": {}, "conditions": {"tested": ["EQ", {"S": "READY"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "S-EQ-different-type", "operation": "update_item", "seed": {"tested": {"N": "0"}}, "conditions": {"tested": ["EQ", {"S": "READY"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "S-NE-equal", "operation": "update_item", "seed": {"tested": {"S": "READY"}}, "conditions": {"tested": ["NE", {"S": "READY"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "S-NE-unequal", "operation": "update_item", "seed": {"tested": {"S": "PENDING"}}, "conditions": {"tested": ["NE", {"S": "READY"}]}, "aws_status": "success"},
+ {"name": "S-NE-missing", "operation": "update_item", "seed": {}, "conditions": {"tested": ["NE", {"S": "READY"}]}, "aws_status": "success"},
+ {"name": "S-NE-different-type", "operation": "update_item", "seed": {"tested": {"N": "0"}}, "conditions": {"tested": ["NE", {"S": "READY"}]}, "aws_status": "success"},
+ {"name": "N-EQ-equal", "operation": "update_item", "seed": {"tested": {"N": "0"}}, "conditions": {"tested": ["EQ", {"N": "0"}]}, "aws_status": "success"},
+ {"name": "N-EQ-unequal", "operation": "update_item", "seed": {"tested": {"N": "1"}}, "conditions": {"tested": ["EQ", {"N": "0"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "N-EQ-missing", "operation": "update_item", "seed": {}, "conditions": {"tested": ["EQ", {"N": "0"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "N-EQ-different-type", "operation": "update_item", "seed": {"tested": {"S": "0"}}, "conditions": {"tested": ["EQ", {"N": "0"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "N-NE-equal", "operation": "update_item", "seed": {"tested": {"N": "0"}}, "conditions": {"tested": ["NE", {"N": "0"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "N-NE-unequal", "operation": "update_item", "seed": {"tested": {"N": "1"}}, "conditions": {"tested": ["NE", {"N": "0"}]}, "aws_status": "success"},
+ {"name": "N-NE-missing", "operation": "update_item", "seed": {}, "conditions": {"tested": ["NE", {"N": "0"}]}, "aws_status": "success"},
+ {"name": "N-NE-different-type", "operation": "update_item", "seed": {"tested": {"S": "0"}}, "conditions": {"tested": ["NE", {"N": "0"}]}, "aws_status": "success"},
+ {"name": "BOOL-EQ-equal", "operation": "update_item", "seed": {"tested": {"BOOL": true}}, "conditions": {"tested": ["EQ", {"BOOL": true}]}, "aws_status": "success"},
+ {"name": "BOOL-EQ-unequal", "operation": "update_item", "seed": {"tested": {"BOOL": false}}, "conditions": {"tested": ["EQ", {"BOOL": true}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "BOOL-EQ-missing", "operation": "update_item", "seed": {}, "conditions": {"tested": ["EQ", {"BOOL": true}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "BOOL-EQ-different-type", "operation": "update_item", "seed": {"tested": {"S": "true"}}, "conditions": {"tested": ["EQ", {"BOOL": true}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "BOOL-NE-equal", "operation": "update_item", "seed": {"tested": {"BOOL": true}}, "conditions": {"tested": ["NE", {"BOOL": true}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "BOOL-NE-unequal", "operation": "update_item", "seed": {"tested": {"BOOL": false}}, "conditions": {"tested": ["NE", {"BOOL": true}]}, "aws_status": "success"},
+ {"name": "BOOL-NE-missing", "operation": "update_item", "seed": {}, "conditions": {"tested": ["NE", {"BOOL": true}]}, "aws_status": "success"},
+ {"name": "BOOL-NE-different-type", "operation": "update_item", "seed": {"tested": {"S": "true"}}, "conditions": {"tested": ["NE", {"BOOL": true}]}, "aws_status": "success"},
+ {"name": "component-update_item-allowed", "operation": "update_item", "seed": {"stack_name": {"S": "stack"}, "component_version_id": {"S": "component"}, "deprecated": {"BOOL": false}, "new_cluster_eligible": {"S": "PENDING"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}], "component_version_id": ["EQ", {"S": "component"}], "deprecated": ["NE", {"BOOL": true}], "new_cluster_eligible": ["NE", {"S": "READY"}]}, "aws_status": "success"},
+ {"name": "component-update_item-ready", "operation": "update_item", "seed": {"stack_name": {"S": "stack"}, "component_version_id": {"S": "component"}, "deprecated": {"BOOL": false}, "new_cluster_eligible": {"S": "READY"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}], "component_version_id": ["EQ", {"S": "component"}], "deprecated": ["NE", {"BOOL": true}], "new_cluster_eligible": ["NE", {"S": "READY"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "component-update_item-deprecated", "operation": "update_item", "seed": {"stack_name": {"S": "stack"}, "component_version_id": {"S": "component"}, "deprecated": {"BOOL": true}, "new_cluster_eligible": {"S": "PENDING"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}], "component_version_id": ["EQ", {"S": "component"}], "deprecated": ["NE", {"BOOL": true}], "new_cluster_eligible": ["NE", {"S": "READY"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "component-update_item-wrong-stack", "operation": "update_item", "seed": {"stack_name": {"S": "other"}, "component_version_id": {"S": "component"}, "deprecated": {"BOOL": false}, "new_cluster_eligible": {"S": "PENDING"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}], "component_version_id": ["EQ", {"S": "component"}], "deprecated": ["NE", {"BOOL": true}], "new_cluster_eligible": ["NE", {"S": "READY"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "component-update_item-wrong-version", "operation": "update_item", "seed": {"stack_name": {"S": "stack"}, "component_version_id": {"S": "other"}, "deprecated": {"BOOL": false}, "new_cluster_eligible": {"S": "PENDING"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}], "component_version_id": ["EQ", {"S": "component"}], "deprecated": ["NE", {"BOOL": true}], "new_cluster_eligible": ["NE", {"S": "READY"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "component-update_item-absent-ne-fields", "operation": "update_item", "seed": {"stack_name": {"S": "stack"}, "component_version_id": {"S": "component"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}], "component_version_id": ["EQ", {"S": "component"}], "deprecated": ["NE", {"BOOL": true}], "new_cluster_eligible": ["NE", {"S": "READY"}]}, "aws_status": "success"},
+ {"name": "component-put_item-allowed", "operation": "put_item", "seed": {"stack_name": {"S": "stack"}, "component_version_id": {"S": "component"}, "deprecated": {"BOOL": false}, "new_cluster_eligible": {"S": "PENDING"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}], "component_version_id": ["EQ", {"S": "component"}], "deprecated": ["NE", {"BOOL": true}], "new_cluster_eligible": ["NE", {"S": "READY"}]}, "aws_status": "success"},
+ {"name": "component-put_item-ready", "operation": "put_item", "seed": {"stack_name": {"S": "stack"}, "component_version_id": {"S": "component"}, "deprecated": {"BOOL": false}, "new_cluster_eligible": {"S": "READY"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}], "component_version_id": ["EQ", {"S": "component"}], "deprecated": ["NE", {"BOOL": true}], "new_cluster_eligible": ["NE", {"S": "READY"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "component-put_item-deprecated", "operation": "put_item", "seed": {"stack_name": {"S": "stack"}, "component_version_id": {"S": "component"}, "deprecated": {"BOOL": true}, "new_cluster_eligible": {"S": "PENDING"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}], "component_version_id": ["EQ", {"S": "component"}], "deprecated": ["NE", {"BOOL": true}], "new_cluster_eligible": ["NE", {"S": "READY"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "component-put_item-wrong-stack", "operation": "put_item", "seed": {"stack_name": {"S": "other"}, "component_version_id": {"S": "component"}, "deprecated": {"BOOL": false}, "new_cluster_eligible": {"S": "PENDING"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}], "component_version_id": ["EQ", {"S": "component"}], "deprecated": ["NE", {"BOOL": true}], "new_cluster_eligible": ["NE", {"S": "READY"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "component-put_item-wrong-version", "operation": "put_item", "seed": {"stack_name": {"S": "stack"}, "component_version_id": {"S": "other"}, "deprecated": {"BOOL": false}, "new_cluster_eligible": {"S": "PENDING"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}], "component_version_id": ["EQ", {"S": "component"}], "deprecated": ["NE", {"BOOL": true}], "new_cluster_eligible": ["NE", {"S": "READY"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "component-put_item-absent-ne-fields", "operation": "put_item", "seed": {"stack_name": {"S": "stack"}, "component_version_id": {"S": "component"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}], "component_version_id": ["EQ", {"S": "component"}], "deprecated": ["NE", {"BOOL": true}], "new_cluster_eligible": ["NE", {"S": "READY"}]}, "aws_status": "success"},
+ {"name": "timestamp-41", "operation": "update_item", "seed": {"stack_name": {"S": "stack"}, "modified": {"N": "41"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}], "modified": ["EQ", {"N": "41"}]}, "aws_status": "success"},
+ {"name": "timestamp-42", "operation": "update_item", "seed": {"stack_name": {"S": "stack"}, "modified": {"N": "42"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}], "modified": ["EQ", {"N": "41"}]}, "aws_status": "ConditionalCheckFailedException"},
+ {"name": "exists-false-present-False", "operation": "update_item", "seed": {"stack_name": {"S": "stack"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}]}, "unchanged": {"modified": {"Exists": false}}, "aws_status": "success"},
+ {"name": "exists-false-present-True", "operation": "update_item", "seed": {"stack_name": {"S": "stack"}, "modified": {"N": "41"}}, "conditions": {"stack_name": ["EQ", {"S": "stack"}]}, "unchanged": {"modified": {"Exists": false}}, "aws_status": "ConditionalCheckFailedException"}
+ ]
+}
diff --git a/compatibility-tests/sdk-test-python/tests/test_dynamodb_legacy_expected.py b/compatibility-tests/sdk-test-python/tests/test_dynamodb_legacy_expected.py
new file mode 100644
index 0000000000..a780f1700e
--- /dev/null
+++ b/compatibility-tests/sdk-test-python/tests/test_dynamodb_legacy_expected.py
@@ -0,0 +1,134 @@
+"""Legacy conditions verified against AWS in us-east-1 on 2026-10-12."""
+
+import json
+import uuid
+from pathlib import Path
+
+import pytest
+from botocore.exceptions import ClientError
+
+
+OBSERVATIONS = json.loads(
+ (Path(__file__).parent / "fixtures/dynamodb-legacy-expected-aws.json").read_text()
+)
+
+
+def legacy_table(dynamodb_client):
+ name = "legacy-expected-" + uuid.uuid4().hex[:12]
+ dynamodb_client.create_table(
+ TableName=name,
+ KeySchema=[{"AttributeName": "pk", "KeyType": "HASH"}],
+ AttributeDefinitions=[{"AttributeName": "pk", "AttributeType": "S"}],
+ BillingMode="PAY_PER_REQUEST",
+ )
+ try:
+ dynamodb_client.get_waiter("table_exists").wait(
+ TableName=name, WaiterConfig={"Delay": 1, "MaxAttempts": 30}
+ )
+ yield name
+ finally:
+ dynamodb_client.delete_table(TableName=name)
+
+
+def write(client, operation, table, seed, expected):
+ request = {"TableName": table, "Expected": expected}
+ if operation == "put_item":
+ request["Item"] = {**seed, "marker": {"S": "after"}}
+ else:
+ request["Key"] = {"pk": seed["pk"]}
+ if operation == "update_item":
+ request["AttributeUpdates"] = {
+ "marker": {"Action": "PUT", "Value": {"S": "after"}}
+ }
+ try:
+ getattr(client, operation)(**request)
+ return "success", None
+ except ClientError as error:
+ assert error.response["ResponseMetadata"]["HTTPStatusCode"] == 400
+ return error.response["Error"]["Code"], error.response["Error"]["Message"]
+
+
[email protected]("operation", ["put_item", "update_item", "delete_item"])
+ "case", OBSERVATIONS["operand_cases"], ids=lambda case: case["label"]
+)
+def test_expected_operands_match_aws(dynamodb_client, legacy_table, operation, case):
+ seed = {"pk": {"S": "row"}, **OBSERVATIONS["metadata"]["operand_seed"]}
+ dynamodb_client.put_item(TableName=legacy_table, Item=seed)
+ status, message = write(
+ dynamodb_client, operation, legacy_table, seed, {"tested": case["condition"]}
+ )
+ stored = dynamodb_client.get_item(
+ TableName=legacy_table, Key={"pk": seed["pk"]}, ConsistentRead=True
+ ).get("Item")
+ expected_stored = seed
+ if case["status"] == "success":
+ expected_stored = (
+ None if operation == "delete_item" else {**seed, "marker": {"S": "after"}}
+ )
+ assert (status, message) == (case["status"], case["message"])
+ assert stored == expected_stored
+
+
+ "case", OBSERVATIONS["valid_pairs"], ids=lambda case: case["name"]
+)
+def test_value_and_attribute_value_list_match_aws(dynamodb_client, legacy_table, case):
+ stored_items = []
+ for operand_field in ["Value", "AttributeValueList"]:
+ seed = {
+ **case["seed"],
+ "pk": {"S": operand_field},
+ "marker": {"S": "before"},
+ }
+ dynamodb_client.put_item(TableName=legacy_table, Item=seed)
+ expected = dict(case.get("unchanged", {}))
+ for field, (operator, operand) in case["conditions"].items():
+ expected[field] = {
+ "ComparisonOperator": operator,
+ operand_field: operand if operand_field == "Value" else [operand],
+ }
+ status, _ = write(
+ dynamodb_client, case["operation"], legacy_table, seed, expected
+ )
+ stored = dynamodb_client.get_item(
+ TableName=legacy_table, Key={"pk": seed["pk"]}, ConsistentRead=True
+ )["Item"]
+ assert status == case["aws_status"]
+ assert stored == {
+ **seed,
+ "marker": {"S": "after" if status == "success" else "before"},
+ }
+ stored_items.append({k: v for k, v in stored.items() if k != "pk"})
+ assert stored_items[0] == stored_items[1]
+
+
[email protected]("expression_key", [False, True])
[email protected]("filter_value", ["7", "8"])
+def test_legacy_key_conditions_with_filter_expression(
+ dynamodb_client, legacy_table, expression_key, filter_value
+):
+ item = {"pk": {"S": "domain"}, "diNumber": {"S": "7"}}
+ dynamodb_client.put_item(TableName=legacy_table, Item=item)
+ request = {
+ "TableName": legacy_table,
+ "ConsistentRead": True,
+ "FilterExpression": "diNumber = :diNumber",
+ "ExpressionAttributeValues": {":diNumber": {"S": filter_value}},
+ }
+ if expression_key:
+ request["KeyConditionExpression"] = "pk = :domain"
+ request["ExpressionAttributeValues"][":domain"] = {"S": "domain"}
+ else:
+ request["KeyConditions"] = {
+ "pk": {
+ "ComparisonOperator": "EQ",
+ "AttributeValueList": [{"S": "domain"}],
+ }
+ }
+ response = dynamodb_client.query(**request)
+ expected_items = [item] if filter_value == "7" else []
+ assert response["Items"] == expected_items
+ assert response["Count"] == len(expected_items)
+ assert response["ScannedCount"] == 1
diff --git a/docs/services/dynamodb.md b/docs/services/dynamodb.md
index c68030c9a6..14bd279811 100644
--- a/docs/services/dynamodb.md
+++ b/docs/services/dynamodb.md
@@ -44,6 +44,27 @@
| `DescribeImport` | Get import status and metadata |
| `ListImports` | List imports, optionally filtered by table ARN |
+## Legacy conditional requests
+
+The native backend accepts `KeyConditions` together with `FilterExpression`.
+For legacy `Expected` conditions it also accepts `ComparisonOperator` with a single
+`Value`, including EQ and NE, just as the live AWS service does. Supplying both
+`Value` and `AttributeValueList`, omitting a required operand, or supplying the wrong
+number of operands returns `ValidationException` without changing the item.
+`NULL` and `NOT_NULL` take no operands.
+
+These behaviors were verified against AWS in `us-east-1` on October 12, 2026:
+40 pairs of equivalent conditional writes, matching and nonmatching queries,
+and 30 operand cases for each of `PutItem`, `UpdateItem` and `DeleteItem`.
+The SDK regression cases and recorded error messages are in
+`compatibility-tests/sdk-test-python/tests/test_dynamodb_legacy_expected.py` and
+`tests/fixtures/dynamodb-legacy-expected-aws.json` within that suite.
+
+AWS's [ExpectedAttributeValue documentation](https://docs.aws.amazon.com/sdk-for-python/v4/reference/clients/dynamodb/structures/ExpectedAttributeValue/)
+describes the parameter families as incompatible more broadly. Floci preserves
+the combinations accepted by the live service; this does not make every mixture
+of legacy and expression parameters valid.
+
## Streams {#streams}
DynamoDB Streams are supported via a separate target (`DynamoDBStreams_20120810`):
diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java
index f17adc1623..e4aae67e4a 100644
--- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java
@@ -918,6 +918,8 @@ public class NativeDynamoDbJsonHandler {
* {@code Exists: false} asks for plain absence.</li>
* <li>{@code Exists: false} forbids a {@code Value}: an attribute cannot be expected to
* hold a value while also being expected to be absent.</li>
+ * <li>A comparison accepts either {@code Value} or {@code AttributeValueList}, but
+ * never both, and must have the operator's required number of operands.</li>
* </ul>
* DynamoDB reports only the first offending entry, so validation stops at the first error.
*/
@@ -948,6 +950,37 @@ public class NativeDynamoDbJsonHandler {
throw legacyExpectedValidationError(
"Value cannot be used when Exists is false for Attribute: " + attrName);
}
+ if (hasValue && condition.has("AttributeValueList")) {
+ throw legacyExpectedValidationError(
+ "Value and AttributeValueList cannot be used together for Attribute: " + attrName);
+ }
+ if (hasComparisonOperator) {
+ validateLegacyComparisonOperands(attrName, condition);
+ }
+ }
+ }
+
+ private void validateLegacyComparisonOperands(String attrName, JsonNode condition) {
+ String operator = condition.get("ComparisonOperator").asText();
+ int required = switch (operator) {
+ case "NULL", "NOT_NULL" -> 0;
+ case "EQ", "NE", "LE", "LT", "GE", "GT", "CONTAINS", "NOT_CONTAINS", "BEGINS_WITH" -> 1;
+ case "BETWEEN" -> 2;
+ case "IN" -> -1;
+ default -> throw legacyExpectedValidationError("Invalid comparison operator");
+ };
+ boolean hasValue = condition.has("Value");
+ boolean hasList = condition.has("AttributeValueList");
+ if (required != 0 && !hasValue && !hasList) {
+ throw legacyExpectedValidationError(
+ "Value or AttributeValueList must be used with ComparisonOperator: "
+ + operator + " for Attribute: " + attrName);
+ }
+ // AWS accepts ComparisonOperator + Value as a single operand, including IN.
+ int count = hasValue ? 1 : hasList ? condition.get("AttributeValueList").size() : 0;
+ if (required == -1 ? count == 0 : count != required) {
+ throw legacyExpectedValidationError(
+ "Invalid number of argument(s) for the " + operator + " ComparisonOperator");
}
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbLegacyExpectedOperandsTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbLegacyExpectedOperandsTest.java
new file mode 100644
index 0000000000..4b2a2b3ceb
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbLegacyExpectedOperandsTest.java
@@ -0,0 +1,102 @@
+package io.github.hectorvent.floci.services.dynamodb;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.storage.InMemoryStorage;
+import io.github.hectorvent.floci.services.dynamodb.model.AttributeDefinition;
+import io.github.hectorvent.floci.services.dynamodb.model.KeySchemaElement;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class DynamoDbLegacyExpectedOperandsTest {
+ private static final String REGION = "us-east-1";
+ private static final String TABLE = "ExpectedOperands";
+ private static final String PREFIX =
+ "1 validation error detected: One or more parameter values were invalid: ";
+ private final ObjectMapper mapper = new ObjectMapper();
+ private DynamoDbService service;
+ private NativeDynamoDbJsonHandler handler;
+ private ObjectNode seed;
+ private ObjectNode key;
+
+ @BeforeEach
+ void setUp() throws Exception {
+ service = new DynamoDbService(new InMemoryStorage<>());
+ handler = new NativeDynamoDbJsonHandler(service, null, null, mapper);
+ service.createTable(TABLE, List.of(new KeySchemaElement("pk", "HASH")),
+ List.of(new AttributeDefinition("pk", "S")), 5L, 5L, REGION);
+ seed = (ObjectNode) mapper.readTree("""
+ {"pk":{"S":"row"},"tested":{"S":"READY"},"marker":{"S":"before"}}
+ """);
+ key = (ObjectNode) mapper.readTree("""
+ {"pk":{"S":"row"}}
+ """);
+ service.putItem(TABLE, seed, REGION);
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"PutItem", "UpdateItem", "DeleteItem"})
+ void rejectsMissingConflictingAndExtraOperandsWithoutChangingItem(String operation) throws Exception {
+ List<String> conditions = List.of(
+ """
+ {"ComparisonOperator":"NE"}
+ """,
+ """
+ {"ComparisonOperator":"EQ","Value":{"S":"OTHER"},"AttributeValueList":[{"S":"READY"}]}
+ """,
+ """
+ {"ComparisonOperator":"EQ","AttributeValueList":[{"S":"READY"},{"S":"OTHER"}]}
+ """,
+ """
+ {"ComparisonOperator":"NOT_NULL","Value":{"S":"READY"}}
+ """);
+ List<String> messages = List.of(
+ "Value or AttributeValueList must be used with ComparisonOperator: NE for Attribute: tested",
+ "Value and AttributeValueList cannot be used together for Attribute: tested",
+ "Invalid number of argument(s) for the EQ ComparisonOperator",
+ "Invalid number of argument(s) for the NOT_NULL ComparisonOperator");
+ for (int index = 0; index < conditions.size(); index++) {
+ ObjectNode request = writeRequest(operation, mapper.readTree(conditions.get(index)));
+ AwsException error = assertThrows(AwsException.class,
+ () -> handler.handle(operation, request, REGION));
+ assertEquals("ValidationException", error.getErrorCode());
+ assertEquals(PREFIX + messages.get(index), error.getMessage());
+ assertEquals(seed, service.getItem(TABLE, key, REGION));
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"PutItem", "UpdateItem", "DeleteItem"})
+ void acceptsComparisonOperatorWithValue(String operation) throws Exception {
+ ObjectNode request = writeRequest(operation, mapper.readTree("""
+ {"ComparisonOperator":"EQ","Value":{"S":"READY"}}
+ """));
+ assertEquals(200, handler.handle(operation, request, REGION).getStatus());
+ }
+
+ private ObjectNode writeRequest(String operation, JsonNode condition) {
+ ObjectNode request = mapper.createObjectNode().put("TableName", TABLE);
+ request.set("Expected", mapper.createObjectNode().set("tested", condition));
+ if ("PutItem".equals(operation)) {
+ ObjectNode replacement = seed.deepCopy();
+ replacement.set("marker", mapper.createObjectNode().put("S", "after"));
+ request.set("Item", replacement);
+ } else {
+ request.set("Key", key);
+ if ("UpdateItem".equals(operation)) {
+ ObjectNode update = mapper.createObjectNode().put("Action", "PUT");
+ update.set("Value", mapper.createObjectNode().put("S", "after"));
+ request.set("AttributeUpdates", mapper.createObjectNode().set("marker", update));
+ }
+ }
+ return request;
+ }
+}