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

Aperta Adatta ai principianti
#8,725 6 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Neeraj111010 ci sta già lavorando.

Dal 1/11/2026.

  • #8741 di @Neeraj111010 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
80/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia in persistence/base.py nel metodo _IdempotencyKeyEncoder.default, che gestisce Enum, date/time, UUID e PurePath. Estendilo per codificare set/frozenset come liste ordinate e bytes come base64. Aggiungi test che verificano che insiemi uguali in ordine diverso producano la stessa chiave e bytes funzioni; esegui la suite secondo AGENTS.md per confermare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Python
Stelle
3.3k
Fork
511
Merge medio
3g 4h
PR unite (30g)
98

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di aws-powertools/powertools-lambda-python

Tutte le issue di aws-powertools/powertools-lambda-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.