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

Offen Anfängerfreundlich
#8,725 6 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@Neeraj111010 arbeitet bereits daran.

Seit 01.11.2026.

  • #8741 von @Neeraj111010 — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
80/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
backend

Rechercherichtung

Beginne in persistence/base.py bei der Methode _IdempotencyKeyEncoder.default, die Enum, date/time, UUID und PurePath behandelt. Erweitere sie, um set/frozenset als sortierte Listen und bytes als base64 zu kodieren. Füge Tests hinzu, die prüfen, dass gleiche Sets in unterschiedlicher Reihenfolge denselben Schlüssel ergeben und bytes funktioniert; führe die Suite gemäß AGENTS.md aus, um zu bestätigen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug good first issue help wanted idempotency

[!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

Vorherrschende Sprache
Python
Sterne
3.3k
Forks
511
Ø Merge
3 T. 8 Std.
Gemergte PRs (30 T.)
92

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus aws-powertools/powertools-lambda-python

Alle Issues in aws-powertools/powertools-lambda-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.