Repository navigation
fix(idempotency): add deterministic support for set, frozenset, and bytes types - #8741
Neeraj111010 wants to merge 1 commit into
Conversation
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
|
blacksoxx
left a comment
There was a problem hiding this comment.
Comment. The encoder change does what #8725 asks and the two insertion orders hashing to one key is the test that matters; one small gap in the docs.
Reviewed head fc3b4a5a against develop at 3b261550; both unchanged just before posting, PR open. Validation: diff read against the current default(); the key=repr fallback is deterministic for equal contents and an element that is not serialisable still fails when the sorted list is encoded, so no silent hash. Not run here: the idempotency suites. History: #8725 is the maintainers' own issue, assigned to you; no earlier PR for these types (searched "idempotency set frozenset bytes", "idempotency set bytes hash", 100 results per query, capped).
[P3] docs/utilities/idempotency.md line 195 lists which values the hash encoder converts (UUID, paths, dates, enums); sets, frozensets (as sorted lists) and bytes (base64) belong in that sentence now, otherwise the docs still say they are unsupported. No unrelated scope changes.
I would merge this with that line added; the decision is with the maintainers.



Issue number: closes #8725
Summary
This PR adds native support for
set,frozenset, andbytestypes to the AWS Lambda Powertools_IdempotencyKeyEncoder. It ensures sets and frozensets are sorted deterministically regardless of insertion order, and encodes bytes using Base64 so they can be securely and reliably hashed and validated in the idempotency utilityChanges
aws_lambda_powertools/utilities/idempotency/persistence/base.py):setandfrozensetby converting them into sorted lists to guarantee identical hashes across varying element insertion orders, with safe fallback sorting (key=repr) for non-comparable items.bytes(base64.b64encode(obj).decode("utf-8")).tests/functional/idempotency/_boto3/test_idempotency_hash_serialization.py):setandbytesfrom unsupported error test cases.test_set_frozenset_and_bytes_supportto validate persistent replay, payload validation, and insertion order determinism.User experience
set,frozenset, orbytesobjects to an idempotent function would raise aTypeErrorbecause they were not JSON serializable or produced non-deterministic hashes due to unordered iteration.Verification
make lint/ruff, passing all style and formatting checks with zero errors or warnings.uv run pytest tests/functional/idempotency/, with 33 functional test cases passing successfully.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.