Bug: output_serializer=PydanticSerializer crashes at import under from __future__ import annotations
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 80/100
Rechercherichtung
Lies aws_lambda_powertools/utilities/idempotency/idempotency.py und serialization/pydantic.py. Ersetze das direkte Lesen von annotations durch typing.get_type_hints(function).get('return') und schütze die Instanziierung mit inspect.isclass, um IdempotencyModelTypeError auszulösen. Füge ein Testmodul hinzu, das from future import annotations mit class- und list[Model]-Formen verwendet. Erledigt bedeutet, dass die neuen Tests bestehen und das Modul ohne TypeError importiert wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
[!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
- Vorherrschende Sprache
- Python
- Sterne
- 3.3k
- Forks
- 511
- Ø Merge
- 3 T. 8 Std.
- Gemergte PRs (30 T.)
- 92
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus aws-powertools/powertools-lambda-python
-
Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocationEvtl. vergeben @lechakrawarthy hat das vor 2 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
aws-powertools/powertools-lambda-python#8728 · 4 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: Redis layer fails the invocation instead of retrying when a record expires between SET NX and GETEvtl. vergeben @coughlmao hat das vor 2 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
aws-powertools/powertools-lambda-python#8727 · 4 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: Redis orphan lock timeout ignores expires_after_seconds and is always 10 secondsEvtl. vergeben @CJstate hat das vor 2 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
aws-powertools/powertools-lambda-python#8726 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: idempotency payloads with set, frozenset or bytes fields cannot be hashedEvtl. vergeben @Neeraj111010 hat das vor 2 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 80/100
aws-powertools/powertools-lambda-python#8725 · 6 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key valueEvtl. vergeben @sumedh-aerram hat das vor 2 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
aws-powertools/powertools-lambda-python#8724 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in aws-powertools/powertools-lambda-python
Ähnliche Issues
-
cost:cheap practicality:seen-in-the-wild severity:medium
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
fairagro/m4.2_advanced_middleware_api#620 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area:security effort:S priority:P2 provider:local-libvirt status:ready type:docs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
randomparity/kdive#3495 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
microsoft/markitdown#2820 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 2 Tagen