question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Not a valid tuple.' when trying to use marshmallow fields.Tuple for argument validation

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
sirosencommented, May 5, 2020

Just as a small follow-up update: this is now available in version 6.1.0 of webargs.

0reactions
lafrechcommented, Apr 29, 2020

@Donovant, would you like to try #509 on your codebase before we merge it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

marshmallow.fields — marshmallow 3.19.0 documentation
:param required: Raise a :exc:`ValidationError` if the field value is not supplied during deserialization. :param allow_none: Set this to `True` if `None` ...
Read more >
Python Marshmallow Field can be two different types
Is there a way to just validate the two types that I want? Something like, value = fields.Str() or fields.List(). python ...
Read more >
marshmallow - Read the Docs
You may not need to output all declared fields every time you use a schema. ... marshmallow, Release 2.21.0 from marshmallow import ValidationError...
Read more >
Python marshmallow Explained [Practical Examples]
Now let us see how we can create a schema using Python marshmallow. ... Str(required = True) # last name and age as...
Read more >
webargs(1) - Arch manual pages
Required arguments "username": fields.Str(required=True), # Validation "password": fields.Str(validate=lambda p: len(p) >= 6), # OR use marshmallow's ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found