Comments (10)
this issue should not occur anymore since release 0.6.1
Feel free to reopen or create new issue if the problem persists.
Jirka
from flask-pydantic.
Hello,
this is interesting. When I add your code into the example app provided in the repository it works fine.
Could you post your whole code? Also in your requirements there is flask-pydantic-spec==0.1.3
and no flask-pydantic
. Maybe there could be some kind of interference with these two libraries.
Jirka
from flask-pydantic.
sorry,flask-pydantic-spec==0.1.3 is other test library. Right requirement is Flask-Pydantic==0.4.0
from flask-pydantic.
I am not able to reproduce your problem. Could you please share a whole minimal example that still produces the error?
from flask-pydantic.
I am not able to reproduce your problem. Could you please share a whole minimal example that still produces the error?
Here is a minimal example:
from flask import Flask
from flask import Blueprint
app = Flask(__name__)
from pydantic import BaseModel
from flask_pydantic import validate
from typing import List
class Query(BaseModel):
query: str
test_bp = Blueprint("test",__name__)
@test_bp.route("/test_route", methods=["GET"])
@validate(query=Query)
def test_route(query:Query):
return {}
if __name__ == "__main__":
app.register_blueprint(test_bp)
app.run(host="0.0.0.0", port="8888")
from flask-pydantic.
Same thing happened to me.
With a little investigation, I think, I found the root cause.
In convert_query_params
, this line
return {
**query_params,
should be
return {
**query_params.to_dict(flat=True), # flat=True is the default
because when request.args is unpacked, dict values become list
rather than str
; in other words, explicit cast is done with to_dict(flat=False)
.
from flask-pydantic.
I am sorry guys, I am running the exact same code as @CharmingZhou posted and still no error (tried both python 3.6 and 3.9). Could You please @yasinyildiza share your minimal example together with your environment setup?
from flask-pydantic.
Python
3.6.2
pip freeze
click==7.1.2
dataclasses==0.8
Flask==1.1.2
Flask-Pydantic==0.6.0
itsdangerous==1.1.0
Jinja2==2.11.3
MarkupSafe==1.1.1
pydantic==1.7.3
Werkzeug==1.0.1
code
import flask
import flask_pydantic
import pydantic
class Query(pydantic.BaseModel):
query: str
app = flask.Flask(__name__)
@app.route('/test')
@flask_pydantic.validate(query=Query)
def test(query:Query):
return flask.jsonify({'query': query.dict()})
if __name__ == '__main__':
app.run(port=5000, debug=True)
I also tried to run the tests after setting up the dev environment (following Contributing instructions). This is the result:
18 failed, 55 passed, 1 warning
from flask-pydantic.
@yasinyildiza @CharmingZhou
It seems that there is a problem with specifically python 3.6.2 version. Unfortunately github won't let me to run tests in github actions using this version see this.
I will try to solve this issue, however I would recommend You to upgrade to at least the newest 3.6 version (3.6.13 at the moment).
from flask-pydantic.
I tested with 0.6.1, and it is working very well.
Thanks a lot @bauerji
from flask-pydantic.
Related Issues (20)
- Untyped decorator makes function "index" untyped
- Using flask-pydantic with Python Dependency Injection Framework HOT 7
- Question: partially populated nested object with required fields
- how to use flask getlist mothed
- Is it possible to automatically recognize the parameters of the view as the path query body? HOT 1
- Error if validation error contains enum.Enum HOT 4
- Why doesn't the `make_json_response` function have a default value for the `by_alias` argument?
- Aliased list query parameters do not work
- pydantic tip...
- add py.typed marker indicating provision of inlined types
- Validator with query params
- Returning empty List instead of raising Exception if response is empty List
- Raise classical Pydantic ValidationError like FastApi HOT 1
- Incompatible with pydantic 2.0.1 - Error validation with GET HOT 10
- AttributeError: 'FieldInfo' object has no attribute 'is_complex' HOT 3
- Validation of ResponseModel? HOT 1
- Pydantic v2's error object contains a ctx field HOT 5
- CI failure for Python3.8 and above
- annotations bug HOT 2
- Support of module pydantic.v1 Since update to Pydantic V2 HOT 1
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 flask-pydantic.