Comments (3)
So, what makes this one a little different is the Optional
. If you left that part off it should work. A fix is coming shortly though for the optional.
from sanic-ext.
@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.
def get(self, name: str, default: Optional[Any] = None) -> Optional[Any]:
"""Return the first value, either the default or actual"""
return super().get(name, [default])[0]
def getlist(self, name: str, default: Optional[Any] = None) -> Optional[Any]:
"""
Return the entire list
"""
return super().get(name, default)
print(request.args.get("q"))
# 1
print(request.args.getlist("q"))
# [1, 2, 3]
Of course, all of these are based on the RequestParameters operations.
If you print request.args
, you will see:
print(request.args)
# {'q': ['1', '2']}
# {'q': ['1']}
It's a dict whose value is a list.
And In sanic-ext validator, the do_validation
function use request.args
as the source of data. You got the validation Error is merited.
Now, you can use dataclass like this to solve this problem temporarily.
@dataclass
class SearchParams:
q: Optional[List[str]] = None
I hope this will help you.
from sanic-ext.
Thanks for let me know the temporary fix. it's really help me 😊😊
Hope the issue will be fixed in future
from sanic-ext.
Related Issues (20)
- [Feature Request] Response Compression
- [Bug] Can't use `pydantic>=2.0` model in OpenAPI definition HOT 1
- [Bug] Can't document/exclude websocket routes with OpenAPI decorator
- [Bug] Subheader "parameter" missing in sanic extensions document
- [Bug] Can't apply openapi decorators to blueprintss' routes
- [Bug]TypeError: listener() got an unexpected keyword argument 'priority' HOT 1
- [Bug] Documentation: dead link to the setting
- Query params validation is completely broken HOT 2
- Question regarding licensing info
- [Bug] Doubly defined objects in the output specification #260 HOT 2
- [Bug] The tags in OpenAPI yaml are not effective
- [Bug] Pydantic query validation with extra data not defined in model raise's KeyError HOT 4
- add project to nix packages
- Add support for scalar.com OpenAPI documentation
- [Bug] Sanic validation extension failed to validate aliased pydantic model field
- [Feature Request] Allow custom localization in `validate` function
- [Bug] Removing handlers in Background Logger extension removes only one handler.
- Question regarding `x-tagGroups` support
- [Bug] pydantic validation exception when validating unknown query strings HOT 2
- [Bug] `validate` should check passed in model type
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sanic-ext.