Skip to content

Commit b4737a8

Browse files
authored
ISSUE-693: Use ExpressionAttributeNames in _put_record (#697)
1 parent e24eb02 commit b4737a8

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Diff for: aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def _put_record(self, data_record: DataRecord) -> None:
121121
logger.debug(f"Putting record for idempotency key: {data_record.idempotency_key}")
122122
self.table.put_item(
123123
Item=item,
124-
ConditionExpression=f"attribute_not_exists({self.key_attr}) OR {self.expiry_attr} < :now",
124+
ConditionExpression="attribute_not_exists(#id) OR #now < :now",
125+
ExpressionAttributeNames={"#id": self.key_attr, "#now": self.expiry_attr},
125126
ExpressionAttributeValues={":now": int(now.timestamp())},
126127
)
127128
except self._ddb_resource.meta.client.exceptions.ConditionalCheckFailedException:

Diff for: tests/functional/idempotency/conftest.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ def expected_params_update_item_with_validation(
122122
@pytest.fixture
123123
def expected_params_put_item(hashed_idempotency_key):
124124
return {
125-
"ConditionExpression": "attribute_not_exists(id) OR expiration < :now",
125+
"ConditionExpression": "attribute_not_exists(#id) OR #now < :now",
126+
"ExpressionAttributeNames": {"#id": "id", "#now": "expiration"},
126127
"ExpressionAttributeValues": {":now": stub.ANY},
127128
"Item": {"expiration": stub.ANY, "id": hashed_idempotency_key, "status": "INPROGRESS"},
128129
"TableName": "TEST_TABLE",
@@ -132,7 +133,8 @@ def expected_params_put_item(hashed_idempotency_key):
132133
@pytest.fixture
133134
def expected_params_put_item_with_validation(hashed_idempotency_key, hashed_validation_key):
134135
return {
135-
"ConditionExpression": "attribute_not_exists(id) OR expiration < :now",
136+
"ConditionExpression": "attribute_not_exists(#id) OR #now < :now",
137+
"ExpressionAttributeNames": {"#id": "id", "#now": "expiration"},
136138
"ExpressionAttributeValues": {":now": stub.ANY},
137139
"Item": {
138140
"expiration": stub.ANY,

0 commit comments

Comments
 (0)