-
Notifications
You must be signed in to change notification settings - Fork 401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: APIGatewayRestResolver with enable_validation=True and custom Response class type hint fails #5038
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi @RynoM! Thanks for reporting this. Actually, this is not a bug, it's just the way Pydantic works. Pydantic can't use In this case, what matters in the from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response
from typing import Dict
app = APIGatewayRestResolver(enable_validation=True, debug=True)
@app.get("/")
def get_result() -> Response[Dict]:
print("We did some work!")
# return {}
return Response(status_code=200, content_type="application/json", body={"message": "Hello, World!"})
def lambda_handler(event: dict, context) -> dict:
return app.resolve(event, context) Please try this and let me know it this worked. |
Thank you for the fast and clear response! This works indeed. Of course after asking the question, re-reading the docs I find the small collapsed note section "Using Response with data validation?". |
|
Expected Behaviour
I expect the type hint to not have any impact on the code running.
Current Behaviour
Adding a type hint to one of the routes results in an error.
Code snippet
Possible Solution
Further description of the error is here in the pydantic docs: https://docs.pydantic.dev/latest/concepts/dataclasses/#use-custom-types
Steps to Reproduce
Adding return type annotation to get_result will break it, removing it works.
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.9
Packaging format used
Lambda Layers
Debugging logs
The text was updated successfully, but these errors were encountered: