File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed 
aws_lambda_powertools/utilities/idempotency 
tests/functional/idempotency Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 1111    IdempotencyInconsistentStateError ,
1212    IdempotencyItemAlreadyExistsError ,
1313    IdempotencyItemNotFoundError ,
14+     IdempotencyKeyError ,
1415    IdempotencyPersistenceLayerError ,
1516    IdempotencyValidationError ,
1617)
@@ -132,6 +133,8 @@ def handle(self) -> Any:
132133            # We call save_inprogress first as an optimization for the most common case where no idempotent record 
133134            # already exists. If it succeeds, there's no need to call get_record. 
134135            self .persistence_store .save_inprogress (event = self .event , context = self .context )
136+         except  IdempotencyKeyError :
137+             raise 
135138        except  IdempotencyItemAlreadyExistsError :
136139            # Now we know the item already exists, we can retrieve it 
137140            record  =  self ._get_idempotency_record ()
Original file line number Diff line number Diff line change @@ -828,3 +828,20 @@ def lambda_handler(event, context):
828828    stubber .assert_no_pending_responses ()
829829    stubber .deactivate ()
830830    assert  "Failed to save in progress record to idempotency store"  ==  e .value .args [0 ]
831+ 
832+ 
833+ def  test_handler_raise_idempotency_key_error (persistence_store : DynamoDBPersistenceLayer , lambda_context ):
834+     # GIVEN raise_on_no_idempotency_key is True 
835+     idempotency_config  =  IdempotencyConfig (event_key_jmespath = "idemKey" , raise_on_no_idempotency_key = True )
836+ 
837+     # WHEN handling the idempotent call 
838+     # AND save_inprogress raises a IdempotencyKeyError 
839+     @idempotent (persistence_store = persistence_store , config = idempotency_config ) 
840+     def  handler (event , context ):
841+         raise  ValueError ("Should not be raised" )
842+ 
843+     # THEN idempotent should re-raise the IdempotencyKeyError 
844+     with  pytest .raises (IdempotencyKeyError ) as  e :
845+         handler ({}, lambda_context )
846+ 
847+     assert  "No data found to create a hashed idempotency_key"  ==  e .value .args [0 ]
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments