-
Notifications
You must be signed in to change notification settings - Fork 421
Cannot return bare Response when enable_validation=True #4085
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
Comments
@nlykkei sorry about that and thank you for opening an issue, I'll look at this first thing in the morning! Godaften :) |
Hi @rubenfonseca, Thanks for your reply. I solved it by providing a type argument to class HelloWorldResponse(BaseModel):
message: str
@app.get(
"/helloworld",
summary="Hello, World!",
description="Hello, World!",
response_description="Hello, World!",
responses={
200: {"description": "Hello, World!"},
},
tags=["hello-world"],
)
@tracer.capture_method
def helloworld() -> Response[HelloWorldResponse]:
logger.info("Hello, World!")
return Response(status_code=200, body=HelloWorldResponse(message="Hello, World!"), content_type="application/json") Nothing is mentioned about this in the docs, neither is there any documentation in code about the usage of the Godmorgen :) |
Thank you for that update! I want to make this clearer in the docs. But looking at the original code, what would be the expected behaviour here? Since we cannot determine the concrete type, we could always skip the validation of the returned data, but I'm worried that this might be unexpected for some users. Any thoughts? |
I like your reasoning. Maybe it would be wrong to skip validation for
Yes, I would update the docs. For new users, there is nothing linking |
Great! Let me work on the docs then! |
@nlykkei can you check the PR to see if it looks ok? Any feedback is appreciated :) |
|
@rubenfonseca It looks great, very clear explanation to new users 🚀 Thank you for the contribution! |
This is now released under 2.37.0 version! |
Expected Behaviour
Response
objects are not validated, but return as-is. Only Pydantic classes should be validatedCurrent Behaviour
Response
objects are validated as if they are Pydantic classes, resulting in the following error:Unable to generate pydantic-core schema for <class 'aws_lambda_powertools.event_handler.api_gateway.Response'>
Code snippet
Possible Solution
No response
Steps to Reproduce
Run the provided sample using e.g. SAM
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.12
Packaging format used
PyPi
Debugging logs
The text was updated successfully, but these errors were encountered: