New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to return list as JSON #4672
Conversation
The failing "Pallets Development Versions" check is due to a missing import in Werkzueg ( |
Looks like that fix should be made in Werkzeug @pgjones |
I think my original hesitation was that returning a dict is explicitly different from returning a database model. Returning a list of database results is probably something a lot more users will try. But I guess it's not that different to say they have to do |
I see. If they don't return a list of objects directly and call jsonify for the list, they will get the same error. Maybe we could update the docs to mention that the ORM/ODM object is not jsonify-able, they need to convert them to a dict or use a serialization library. |
Another potential confusion now that we support returning iterators/generators is that you're going to get very different results doing |
This adds support to serializing list return values to JSON, like what we did for the dictionary:
There are some discusses related to this feature in #3111, and the concern is the list return value looks too much like the tuple. Maybe we can rethink about this feature? I propose this because the following reasons:
[1, 2, 3]
and(1, 2, 3)
, and people usually return tuple items without the bracket in the view function.If this change is acceptable, I will update the docs and changelog.
Sorry for break the "zero status". :P
Checklist:
CHANGES.rst
summarizing the change and linking to the issue... versionchanged::
entries in any relevant code docs.pre-commit
hooks and fix any issues.pytest
andtox
, no tests failed.