Skip to content

Commit a0878d8

Browse files
committed
Ignore mypy arg-type error with ConditionalCheckFailedException
1 parent e4a07c7 commit a0878d8

File tree

1 file changed

+10
-8
lines changed
  • aws_lambda_powertools/utilities/idempotency/persistence

1 file changed

+10
-8
lines changed

aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,20 @@ def _put_record(self, data_record: DataRecord) -> None:
243243
":now_in_millis": {"N": str(int(now.timestamp() * 1000))},
244244
":inprogress": {"S": STATUS_CONSTANTS["INPROGRESS"]},
245245
},
246-
**self.return_value_on_condition, # type: ignore
246+
**self.return_value_on_condition, # type: ignore[arg-type]
247247
)
248248
except ClientError as exc:
249249
error_code = exc.response.get("Error", {}).get("Code")
250250
if error_code == "ConditionalCheckFailedException":
251-
old_data_record = self._item_to_data_record(exc.response["Item"]) if "Item" in exc.response else None
252-
if old_data_record is not None:
251+
try:
252+
item = exc.response["Item"] # type: ignore[typeddict-item]
253+
except KeyError:
254+
logger.debug(
255+
f"Failed to put record for already existing idempotency key: {data_record.idempotency_key}",
256+
)
257+
raise IdempotencyItemAlreadyExistsError() from exc
258+
else:
259+
old_data_record = self._item_to_data_record(item)
253260
logger.debug(
254261
f"Failed to put record for already existing idempotency key: "
255262
f"{data_record.idempotency_key} with status: {old_data_record.status}, "
@@ -265,11 +272,6 @@ def _put_record(self, data_record: DataRecord) -> None:
265272

266273
raise IdempotencyItemAlreadyExistsError(old_data_record=old_data_record) from exc
267274

268-
logger.debug(
269-
f"Failed to put record for already existing idempotency key: {data_record.idempotency_key}",
270-
)
271-
raise IdempotencyItemAlreadyExistsError() from exc
272-
273275
raise
274276

275277
@staticmethod

0 commit comments

Comments
 (0)