Skip to content

Bug: idempotency payloads with set, frozenset or bytes fields cannot be hashed #8725

Open

Description

@leandrodamascena

Warning

For contributors, human or agent. Comment here to claim this issue and wait for the assignment before opening a PR; if two PRs show up, the assignee's stays. AI-assisted work is welcome, say so in the PR and tell us how you verified it: run the tests yourself and paste what you saw, do not describe runs you did not do. Read AGENTS.md first, it has the commands and the rules the CI enforces. This goes into 3.41.0.

Expected Behaviour

A dataclass or Pydantic payload with set, frozenset or bytes fields can be used as the idempotency payload; the key hash is computed deterministically.

Current Behaviour

_IdempotencyKeyEncoder in persistence/base.py handles Enum, date/time, UUID and PurePath only. A set field makes the key computation fail with IdempotencyPersistenceLayerError: Failed to save in progress record to idempotency store - Object of type set is not JSON serializable, which reads like a store outage rather than an unsupported payload.

Code snippet

from dataclasses import dataclass
from aws_lambda_powertools.utilities.idempotency import idempotent_function

@dataclass
class Payload:
    id: int
    tags: set

@idempotent_function(data_keyword_argument="payload", persistence_store=layer)
def process(payload: Payload):
    return "ok"

process(payload=Payload(1, {"a"}))  # IdempotencyPersistenceLayerError ... Object of type set is not JSON serializable

Possible Solution

Extend _IdempotencyKeyEncoder.default: encode set/frozenset as a sorted list (sort by repr when elements are not comparable) and bytes as base64. Add tests asserting that the same payload with the same set in a different insertion order produces the same key, and that bytes works.

Item 8 of the Idempotency audit in #8603. No AWS resources needed.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Debugging logs

No response

Activity

  1. added this to the 3.41.0 milestone on Oct 31, 2026
  2. powertools-for-aws-oss-automation commented on Oct 31, 2026

    @powertools-for-aws-oss-automation

    Note

    For those interested in contributing, please leave a comment below so that we can assign the issue to you and make sure we don't duplicate efforts. If you have any further questions, please don't hesitate to ask below or on our Discord server.

  3. Neeraj111010 commented on Oct 31, 2026

    @Neeraj111010

    HI @leandrodamascena
    I would like to claim this issue! I'll work on extending _IdempotencyKeyEncoder to support set, frozenset, and bytes, and add the requested unit tests.

  4. leandrodamascena commented on Nov 1, 2026

    @leandrodamascena
    ContributorAuthor

    @Neeraj111010 it's yours, assigning you now. Go ahead with the PR, and say in the description how you ran the tests.

  5. Neeraj111010 commented on Nov 1, 2026

    @Neeraj111010

    Hi @leandrodamascena! Just wanted to drop a quick note that I've got everything wrapped up here. All 33 tests are passing cleanly and lint checks are completely clear.

    Thanks again!

  6. anishsinghhh3-bit commented on Nov 2, 2026

    @anishsinghhh3-bit

    I would like to work on this issue.

  7. leandrodamascena commented on Nov 2, 2026

    @leandrodamascena
    ContributorAuthor

    Thanks @anishsinghhh3-bit, this one is already assigned to @Neeraj111010. The Logger audit in #8730 becomes issues this week, keep an eye on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomershelp wantedCould use a second pair of eyes/handsidempotencyIdempotency utility

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions