Bug: output_serializer=PydanticSerializer crashes at import under from __future__ import annotations
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 80/100
Hướng nghiên cứu
Đọc aws_lambda_powertools/utilities/idempotency/idempotency.py và serialization/pydantic.py. Thay thế việc đọc trực tiếp annotations bằng typing.get_type_hints(function).get('return') và bảo vệ việc khởi tạo bằng inspect.isclass để ném ra IdempotencyModelTypeError. Thêm một module kiểm thử sử dụng from future import annotations với các dạng class và list[Model]. Xong nghĩa là các bài kiểm thử mới qua và module được import mà không có TypeError.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
[!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
- Ngôn ngữ chính
- Python
- Star
- 3.3k
- Fork
- 511
- Merge trung bình
- 3 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 92
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aws-powertools/powertools-lambda-python
-
Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocationCó thể đã có người làm @lechakrawarthy đã nhận 1 ngày trước. Đang mởbug good first issue help wanted idempotency
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
aws-powertools/powertools-lambda-python#8728 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug: Redis layer fails the invocation instead of retrying when a record expires between SET NX and GETCó thể đã có người làm @coughlmao đã nhận 1 ngày trước. Đang mởbug good first issue help wanted idempotency
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
aws-powertools/powertools-lambda-python#8727 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug: Redis orphan lock timeout ignores expires_after_seconds and is always 10 secondsCó thể đã có người làm @CJstate đã nhận 1 ngày trước. Đang mởbug good first issue help wanted idempotency
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
aws-powertools/powertools-lambda-python#8726 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug: idempotency payloads with set, frozenset or bytes fields cannot be hashedCó thể đã có người làm @Neeraj111010 đã nhận 1 ngày trước. Đang mởbug good first issue help wanted idempotency
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
aws-powertools/powertools-lambda-python#8725 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key valueCó thể đã có người làm @sumedh-aerram đã nhận 1 ngày trước. Đang mởbug good first issue help wanted idempotency
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
aws-powertools/powertools-lambda-python#8724 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của aws-powertools/powertools-lambda-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
huggingface/smolagents#3106 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
area:scripts area:tests bug priority:later
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Ikalus1988/MisakaNet#4358 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Discovered ports from service discovery are never propagated to modules in Module.load()Có thể đã có người làm @vishalmore90 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
OWASP/Nettacker#1828 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
aws-samples/sample-per-model-bedrock#708 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
maintenance
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100