@@ -243,13 +243,20 @@ def _put_record(self, data_record: DataRecord) -> None:
243
243
":now_in_millis" : {"N" : str (int (now .timestamp () * 1000 ))},
244
244
":inprogress" : {"S" : STATUS_CONSTANTS ["INPROGRESS" ]},
245
245
},
246
- ** self .return_value_on_condition , # type: ignore
246
+ ** self .return_value_on_condition , # type: ignore[arg-type]
247
247
)
248
248
except ClientError as exc :
249
249
error_code = exc .response .get ("Error" , {}).get ("Code" )
250
250
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 )
253
260
logger .debug (
254
261
f"Failed to put record for already existing idempotency key: "
255
262
f"{ data_record .idempotency_key } with status: { old_data_record .status } , "
@@ -265,11 +272,6 @@ def _put_record(self, data_record: DataRecord) -> None:
265
272
266
273
raise IdempotencyItemAlreadyExistsError (old_data_record = old_data_record ) from exc
267
274
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
-
273
275
raise
274
276
275
277
@staticmethod
0 commit comments