Bug: output_serializer=PydanticSerializer crashes at import under from __future__ import annotations

Ouverte Adaptée aux débutants
#8,722 6 commentaires 0 réactions 1 personne assignée Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@sumedh-aerram y travaille déjà.

Depuis le 1/11/2026.

  • #8738 par @sumedh-aerram — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
80/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
aws, python
Domaine
backend

Piste de recherche

Lisez aws_lambda_powertools/utilities/idempotency/idempotency.py et serialization/pydantic.py. Remplacez la lecture directe de annotations par typing.get_type_hints(function).get('return') et protégez l'instanciation en utilisant inspect.isclass pour lever IdempotencyModelTypeError. Ajoutez un module de test utilisant from future import annotations avec les formes class et list[Model]. Fait signifie que les nouveaux tests passent et le module est importé sans TypeError.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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

output_serializer=PydanticSerializer (the class form, where the model is taken from the return annotation) works in a module that uses from __future__ import annotations, which is the default style in this repository and in most modern codebases.

Current Behaviour

Under PEP 563 the return annotation is a string, and idempotent_function passes function.__annotations__["return"] straight to PydanticSerializer.instantiate, which does issubclass(str, BaseModel) and raises TypeError: issubclass() arg 1 must be a class at decoration time, so the module fails to import. -> list[Model] has the same problem.

Code snippet
from __future__ import annotations

from pydantic import BaseModel
from aws_lambda_powertools.utilities.idempotency import idempotent_function
from aws_lambda_powertools.utilities.idempotency.serialization.pydantic import PydanticSerializer

class OrderOutput(BaseModel):
    order_id: int

@idempotent_function(data_keyword_argument="order", persistence_store=layer, output_serializer=PydanticSerializer)
def process(order: dict) -> OrderOutput:  # TypeError: issubclass() arg 1 must be a class, at import
    return OrderOutput(order_id=1)
Possible Solution

In aws_lambda_powertools/utilities/idempotency/idempotency.py, resolve the annotation with typing.get_type_hints(function).get("return") instead of reading __annotations__, and in serialization/pydantic.py guard instantiate with inspect.isclass so a non-class annotation raises IdempotencyModelTypeError with a clear message instead of TypeError. Add a test module that uses from __future__ import annotations and the class form, for a single model and for list[Model].

Item 5 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

Langage dominant
Python
Étoiles
3.3k
Forks
511
Merge moyen
3 j 8 h
PR mergées (30 j)
92

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de aws-powertools/powertools-lambda-python

Toutes les issues de aws-powertools/powertools-lambda-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.