-
Notifications
You must be signed in to change notification settings - Fork 428
Validation-Inconsistency on REST-API #4125
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
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi @dschro-1993 can you show me your api handler code that uses |
Handler:
Router:
Model:
|
Can you please tell me which Pydantic version are you using? I've just deployed this code for a test: from aws_lambda_powertools import Logger
from aws_lambda_powertools.event_handler import (
APIGatewayRestResolver,
)
from aws_lambda_powertools.event_handler.api_gateway import Router
from pydantic import Field, BaseModel
logger = Logger()
class Foo(BaseModel):
AccountId: str = Field(pattern=r"^\d{12}$")
router = Router()
@router.post(
"/foo",
)
def helloworld(foo: Foo) -> dict:
logger.info("Hello, World!", foo=foo)
return {"accountId": foo.AccountId}
app = APIGatewayRestResolver(enable_validation=True)
app.include_router(router)
@logger.inject_lambda_context
def lambda_handler(event, context):
return app.resolve(event, context) |
I use the Powertools lambda layer arm64 in its latest version:
|
Oh damn, that layer is built upon Pydantic v1, correct? So I would have to bundle v2 on my own if I want to see v2 behaviour in my lambda? |
Let me try locally with v1 first to understand if this is the cause of problem |
Got it, with Pydantic v1 you have to use ![]() We have an issue collecting interest for a managed Layer that includes Pydantic v2. Can you add your +1 there? If this solves your problem, let me know if we can close this issue :) |
Thanks for your investigation, that was very helpful! |
Awesome! Thank you for opening this report :) Closing it for now |
|
Expected Behaviour
Hey Guys, when I create a BaseModel like this
And create an Instance of it like this:
you will see the following exception:
If I let the APIGatewayRestResolver do the validation implicitly:
And pass a payload to the endpoint like:
it is accepted/valid...do you know why that is?
When
min_length
andmax_length
is used for validation only, I see the expected behaviour...But
pattern
seems to be skipped/iqnored when validation is done implicitly.Any help is appreciated.
Current Behaviour
APIGatewayRestResolver should return same Exception and 422 when payload does not match pattern.
Code snippet
see above
Possible Solution
No response
Steps to Reproduce
see above
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.12
Debugging logs
No response
The text was updated successfully, but these errors were encountered: