'Not a valid tuple.' when trying to use marshmallow fields.Tuple for argument validation
See original GitHub issueI’m trying to use the marshmallow fields.Tuple for querystring argument validation on a GET request using Flask. The issue I’m running into is that no matter what type of object I declare and no matter what I use in the request, I always get the default ‘Not a valid tuple.’ response. I have tried using a tuple of size 1 and 2; using fields.String and/or fields.Integer, etc with the same result.
-
I’m using Python 3.6.9 with these dependencies: anyjson==0.3.3 apipkg==1.5 arrow==0.15.5 attrs==19.3.0 backports.functools-lru-cache==1.6.1 cassandra-driver==3.22.0 Cerberus==1.3.2 certifi==2019.11.28 cffi==1.13.2 chardet==3.0.4 click==7.1.1 execnet==1.7.1 Flask==1.1.1 Flask-Cors==3.0.8 funcsigs==1.0.2 futures==3.1.1 geomet==0.1.2 gevent==1.4.0 greenlet==0.4.13 gunicorn==20.0.4 idna==2.9 importlib-metadata==1.6.0 itsdangerous==1.1.0 Jinja2==2.11.1 jsonklog==0.15.0 MarkupSafe==1.1.1 marshmallow==3.5.1 neurolab==0.3.5 numpy==1.18.1 pluggy==0.13.1 py==1.8.1 pyaml==20.3.1 pymongo==3.10.1 pytest==3.3.0 pytest-forked==0.2 pytest-xdist==1.20.1 python-dateutil==2.8.1 PyYAML==5.3.1 readline==6.2.4.1 requests==2.23.0 six==1.14.0 urllib3==1.25.8 webargs==6.0.0 Werkzeug==1.0.0 zipp==3.1.0
-
Here is an example of what I’m trying to do:
from flask import Flask
from webargs.flaskparser import parser, use_kwargs
from marshmallow import EXCLUDE, fields, Schema
app = Flask(__name__)
@app.errorhandler(422)
def custom_handler(error):
errors = []
if 'query' in error.data['messages']:
for arg in error.data['messages']['query']:
for item in error.data['messages']['query'][arg]:
errors.append(item)
return str(errors), 400
class test_schema(Schema):
class Meta:
unknown = EXCLUDE
strict = True
test_tup = fields.Tuple((fields.Integer(required=True), fields.Integer(required=True)), required=True)
@app.route('/test/', strict_slashes=False)
@parser.use_kwargs(test_schema, location='query')
def test_the_mallow(**kwargs):
return "True"
- Finally, here are a couple example url’s I’ve tried: localhost:2300/test/?test_tup=[0,0] localhost:2300/test/?test_tup=(0,0) localhost:2300/test/?test_tup=0,0
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Just as a small follow-up update: this is now available in version 6.1.0 of webargs.
@Donovant, would you like to try #509 on your codebase before we merge it?