Dumping collections does not work with marshmallow 3.5.1 / Flask 1.1.1
See original GitHub issue$ cat test.py
from flask import Flask
from flask_marshmallow import Marshmallow
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
db = SQLAlchemy(app)
ma = Marshmallow(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
class UserSchema(ma.Schema):
class Meta:
fields = ("id", "name")
user_schema = UserSchema()
users_schema = UserSchema(many=True)
@app.route("/api/users/")
def users():
all_users = User.query.all()
return users_schema.dump(all_users)
@app.route("/api/users/<id>")
def user_detail(id):
user = User.query.get(id)
return user_schema.dump(user)
dump(user)
works fine
$ curl localhost:5000/api/users/1
{
"id": 1,
"name": "John"
}
dump(all_users)
fails:
$ curl -L localhost:5000/api/user
[...]
Traceback (most recent call last):
File "venv/lib/python3.7/site-packages/flask/app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "venv/lib/python3.7/site-packages/flask/app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "venv/lib/python3.7/site-packages/flask/app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "venv/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "venv/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
return self.finalize_request(rv)
File "venv/lib/python3.7/site-packages/flask/app.py", line 1967, in finalize_request
response = self.make_response(rv)
File "venv/lib/python3.7/site-packages/flask/app.py", line 2130, in make_response
" {rv.__class__.__name__}.".format(rv=rv)
TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a list.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Upgrading to Newer Releases — marshmallow 3.19.0 ...
It would work provided the Schema was only used for dumping. When loading, the behaviour was undefined. In marshmallow 3, all but one...
Read more >Flask-Marshmallow
Flask -Marshmallow is a thin integration layer for Flask (a Python web ... You can now use your schema to dump and load...
Read more >Marshmallow returning empty JSON after dumping
I am trying to implement a restful API with Flask using flask-restful, flask-sqlalchemy and flask-marshmallow. I am aware there are many ...
Read more >Software Packages in "jammy", Subsection python
... python3-aptdaemon (1.1.1+bzr982-0ubuntu39): Python 3 module for the server ... fitting and Bayesian uncertainty modeling for inverse problems (Python 3) ...
Read more >flask-marshmallow
Flask -Marshmallow is a thin integration layer for Flask (a Python web framework) and marshmallow (an object serialization/deserialization library) that adds ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@deckar01 Indeed, the bug I’m talking about was caused by my own code.
@spack971 That appears to be unrelated. Can you open a separate issue?