Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ def _get_hashed_idempotency_key(self, data: dict[str, Any]) -> str | None:

@staticmethod
def is_missing_idempotency_key(data) -> bool:
if isinstance(data, (tuple, list, dict)):
if isinstance(data, dict):
# Iterating a dict directly walks its keys, not its values, so a dict of
# {"user": None, "order": None} (e.g. from a JMESPath multi-select expression
# over fields that are all absent from the event) would otherwise be treated
# as present just because its keys are non-None strings.
return all(x is None for x in data.values())
elif isinstance(data, (tuple, list)):
return all(x is None for x in data)
elif isinstance(data, (int, float, bool)):
return False
Expand Down
9 changes: 9 additions & 0 deletions tests/functional/idempotency/_boto3/test_idempotency.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,15 @@
assert BasePersistenceLayer.is_missing_idempotency_key((None, None))
# GIVEN a dict of Nones THEN is_missing_idempotency_key is True
assert BasePersistenceLayer.is_missing_idempotency_key({None: None})
# GIVEN a dict with non-None keys but all-None values (e.g. from a JMESPath
# multi-select expression over event fields that are all absent) THEN
# is_missing_idempotency_key is True. Iterating a dict directly walks its keys,
# not its values, so this case is not covered by the {None: None} case above,
# whose key happens to also be None.
assert BasePersistenceLayer.is_missing_idempotency_key({"user": None, "order": None})

# GIVEN a dict with a real value THEN is_missing_idempotency_key is False
assert BasePersistenceLayer.is_missing_idempotency_key({"user": "abc"}) is False

# GIVEN True THEN is_missing_idempotency_key is False
assert BasePersistenceLayer.is_missing_idempotency_key(True) is False
Expand Down Expand Up @@ -1624,7 +1633,7 @@
def dummy_handler(event, context):
return {"message": "hi"}

with pytest.warns(PowertoolsUserWarning, match="Disabling idempotency is intended for development environments*"):

Check warning on line 1636 in tests/functional/idempotency/_boto3/test_idempotency.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this warning test to have only one invocation possibly emitting a warning.

See more on https://sonarcloud.io/project/issues?id=aws-powertools_powertools-lambda-python&issues=AaAHlYIo3ej0ChNoPQEM&open=AaAHlYIo3ej0ChNoPQEM&pullRequest=8391
dummy(data=mock_event)
dummy_handler(mock_event, lambda_context)

Expand Down