You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When processing the /v1/api/user/register route, a KeyError: 'a' occurs during the validation process of sanic_ext. Specifically, in the clean_data function located in sanic_ext/extras/validation/clean.py, the code attempts to process each key-value pair of the request data using hints[key], but the hints dictionary does not contain the key 'a'. This indicates that 'a' is an extra field, and the sanic_ext validation flow does not handle this extra field correctly. Although extra = Extra.ignore might have been set in the UserRegisterSchema, the internal validation logic of sanic_ext in the clean_data function does not adhere to this setting.
Code snippet
from pydantic import BaseModel
class UserRegisterSchema(BaseModel):
class Config:
extra = ‘ignore’
The sanic_ext validation process should handle extra fields according to the extra = Extra.ignore setting in the UserRegisterSchema, and no KeyError should occur. The clean_data function should either skip extra fields or handle them gracefully without raising a KeyError.
How do you run Sanic?
Sanic CLI
Operating System
Windows
Sanic Version
24.12.0
Additional context
Set up a Sanic application with sanic_ext installed.
Define a UserRegisterSchema with extra = Extra.ignore in its Config class.
Create a route /v1/api/user/register with validation using sanic_ext.
Send a request to /v1/api/user/register that includes an extra field 'a' in the request data.
Observe the error when sanic_ext attempts to validate the request data in the clean_data function.
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Describe the bug
When processing the /v1/api/user/register route, a KeyError: 'a' occurs during the validation process of sanic_ext. Specifically, in the clean_data function located in sanic_ext/extras/validation/clean.py, the code attempts to process each key-value pair of the request data using hints[key], but the hints dictionary does not contain the key 'a'. This indicates that 'a' is an extra field, and the sanic_ext validation flow does not handle this extra field correctly. Although extra = Extra.ignore might have been set in the UserRegisterSchema, the internal validation logic of sanic_ext in the clean_data function does not adhere to this setting.
Code snippet
from pydantic import BaseModel
class UserRegisterSchema(BaseModel):
class Config:
extra = ‘ignore’
@user_bp.post("/register")
@Validate(form= UserRegisterSchema)
async def register_user_handle(request: Request, body: UserRegisterSchema) -> HTTPResponse:
Expected Behavior
The sanic_ext validation process should handle extra fields according to the extra = Extra.ignore setting in the UserRegisterSchema, and no KeyError should occur. The clean_data function should either skip extra fields or handle them gracefully without raising a KeyError.
How do you run Sanic?
Sanic CLI
Operating System
Windows
Sanic Version
24.12.0
Additional context
The text was updated successfully, but these errors were encountered: