Open ob1-dev opened 7 hours ago
Thanks for opening your first issue here! We'll come back to you as soon as we can. In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link
For others experiencing the issue that, like me, was dependent on this behaviour to go from SQLAlchemy objects to JSON without really knowing the internals of pydantic, here is the workaround
enable_validation=True
from APIGatewayRestResolver
pydantic
model perform a model_validate(ORM_OBJECT)
and then model_dump_json()
If my example above adding an assumed ORM object
@app.get("/test")
@tracer.capture_method
def test() -> TestModel:
ORM_OBJECT = method_to_go_get_thing_from_db()
return TestModel.model_validate(ORM_OBJECT).model_dump_json()
Hey @ob1-dev! Thanks for reporting this! I'm able to reproduce the behavior here and I'm going to check the code to see what is going on.
Expected Behaviour
Given the documentation, I would have expected the Validation to be skipped in the situation a middleware responds before the request gets to the route handler.
Current Behaviour
Current behaviour is that my error handler captures a the raise in the OpenAPI validation
Code snippet
Possible Solution
Perhaps the support of the Union of responses from an endpoint, or in the event a request doesn't make it to the route that Validation isn't performed.
Steps to Reproduce
template.yml
pyproject.toml
Preparing the requirements.txt
SAM Build and Local Start-API
Browse to localhost
Hitting specifically
http://localhost:3000/test
will now trigger the validation errorPowertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.12
Packaging format used
Lambda Layers
Debugging logs