Closed
Description
Expected Behaviour
Hey Guys, when I create a BaseModel like this
class Foo(BaseModel):
AccountId: str = Field(pattern=r"^\d{12}$")
And create an Instance of it like this:
foo = Foo(AccountId="12345678901a")
you will see the following exception:
...should match pattern '^\d{12}$' [type=pattern_mismatch, input_value='12345678901a', input_type=str]
If I let the APIGatewayRestResolver do the validation implicitly:
api = event_handler.APIGatewayRestResolver(
enable_validation = True
)
And pass a payload to the endpoint like:
{"AccountId": "12345678901a"}
it is accepted/valid...do you know why that is?
When min_length
and max_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
Metadata
Metadata
Assignees
Type
Projects
Status
Shipped