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
Describe the bug
I'm following this tutorial https://sanic.dev/en/plugins/sanic-ext/validation.html#implementation .
with define dataclass attribute with optional paramater,
it will return 400 , if the query params q have value ex q=123123
without value it will work without problem
I also found the same issue when using pydantic
Screenshots
To Reproduce
from dataclasses import dataclass, asdict
from typing import Optional
from sanic import Sanic
from sanic.response import json
from sanic_ext import validate
app = Sanic("Sanic-APP")
@dataclass
class SearchParams:
q: Optional[str] = None
@app.route("/")
@validate(query=SearchParams)
async def handler(request, query: SearchParams):
return json(asdict(query))
Expected behavior
when the dataclass attribute is Optional, it should not error when we send the query params with value ex ?q=123456
Environment (please complete the following information):
OS: Mac Catalina v10.15.7
Browser Chrome
Version 103.0.5060.53
The text was updated successfully, but these errors were encountered:
@weiztech Hi, there.
In GET method, One parameter can have multiple values, like this:
http://localhost:3000/?q=1&q=2&q=3
Most of the time, you don't need to use this feature. one parameter can have only one value.
So, sanic do some process in RequestParameters object.
defget(self, name: str, default: Optional[Any] =None) ->Optional[Any]:
"""Return the first value, either the default or actual"""returnsuper().get(name, [default])[0]
defgetlist(self, name: str, default: Optional[Any] =None) ->Optional[Any]:
""" Return the entire list """returnsuper().get(name, default)
Describe the bug
I'm following this tutorial https://sanic.dev/en/plugins/sanic-ext/validation.html#implementation .
with define
dataclass
attribute with optional paramater,it will return 400 , if the query params
q
have value exq=123123
without value it will work without problem
I also found the same issue when using
pydantic
Screenshots
To Reproduce
Expected behavior
when the dataclass attribute is
Optional
, it should not error when we send the query params with value ex?q=123456
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: