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() +) + + +@pytest.fixture +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"] + + +@pytest.mark.parametrize("operation", ["put_item", "update_item", "delete_item"]) +@pytest.mark.parametrize( + "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 + + +@pytest.mark.parametrize( + "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] + + +@pytest.mark.parametrize("expression_key", [False, True]) +@pytest.mark.parametrize("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. *