Skip to content

fix(idempotency): Correctly handle save_inprogress errors #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aws_lambda_powertools/utilities/idempotency/idempotency.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def handle(self) -> Any:
# Now we know the item already exists, we can retrieve it
record = self._get_idempotency_record()
return self._handle_for_status(record)
except Exception as exc:
raise IdempotencyPersistenceLayerError("Failed to save in progress record to idempotency store") from exc

return self._call_lambda_handler()

Expand Down
22 changes: 22 additions & 0 deletions tests/functional/idempotency/test_idempotency.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,3 +775,25 @@ def test_custom_jmespath_function_overrides_builtin_functions(
# WHEN calling _get_hashed_idempotency_key
# THEN raise unknown function
persistence_store._get_hashed_idempotency_key({})


def test_idempotent_lambda_save_inprogress_error(persistence_store: DynamoDBPersistenceLayer):
# GIVEN a miss configured persistence layer
# like no table was created for the idempotency persistence layer
stubber = stub.Stubber(persistence_store.table.meta.client)
stubber.add_client_error("put_item", "ResourceNotFoundException")
stubber.activate()

@idempotent(persistence_store=persistence_store)
def lambda_handler(event, context):
return {}

# WHEN handling the idempotent call
# AND save_inprogress raises a ClientError
with pytest.raises(IdempotencyPersistenceLayerError) as e:
lambda_handler({}, {})

# THEN idempotent should raise an IdempotencyPersistenceLayerError
stubber.assert_no_pending_responses()
stubber.deactivate()
assert "Failed to save in progress record to idempotency store" == e.value.args[0]