-
-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Description
Describe the bug
Sanic validation extension failed to validate aliased field name in query parameter, and original non-aliased field name passed validation.
This is not a pydantic validation failure (both aliased and non-aliased field name passed validation when using model_validate method).
To Reproduce
from sanic import Sanic, response, request
from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel
from sanic_ext import validate
class TestQuery(BaseModel):
model_config = ConfigDict(
alias_generator=to_camel,
populate_by_name=True
)
request_uri: str = Field(str, title="request path", description="API path", example='/test', required=True)
app = Sanic("Example")
@app.get('/test')
@validate(query=TestQuery)
async def handler(request: request.Request, query: TestQuery):
return response.empty()
if __name__ == '__main__':
app.run()
# Unexpected failure. Return 500
curl <the-url>/test?requertUri=/test
# Works as expected. Return 204
curl <the-url>/test?requert_uri=/test
Expected behavior
Sanic validation extension need to check aliased field name.
# Expected behviour is to return 204
curl <the-url>/test?requertUri=/test
Environment (please complete the following information):
OS: Ubuntu
Browser: N/A
Version
sanic==23.12.1
sanic-ext==23.12.0
sanic-routing==23.12.0
Related issue
#247
Metadata
Metadata
Assignees
Labels
No labels