Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow to return list as JSON#4672

Merged
davidism merged 3 commits intopallets:mainfrom
greyli:return-list
Jul 3, 2022
Merged

Allow to return list as JSON#4672
davidism merged 3 commits intopallets:mainfrom
greyli:return-list

Conversation

@greyli
Copy link
Contributor

@greyligreyli commentedJul 3, 2022
edited by davidism
Loading

This adds support to serializing list return values to JSON, like what we did for the dictionary:

@app.route('/')defindex():return ['this','will','become','JSON']

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:

If this change is acceptable, I will update the docs and changelog.

Sorry for break the "zero status". :P

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry inCHANGES.rst summarizing the change and linking to the issue.
  • Add.. versionchanged:: entries in any relevant code docs.
  • Runpre-commit hooks and fix any issues.
  • Runpytest andtox, no tests failed.

@greyli
Copy link
ContributorAuthor

greyli commentedJul 3, 2022
edited
Loading

The failing "Pallets Development Versions" check is due to a missing import in Werkzueg (werkzeug.routing.RoutingException), I will make a PR to fix it later.

@davidism
Copy link
Member

davidism commentedJul 3, 2022
edited
Loading

Looks like that fix should be made in Werkzeug@pgjones

@davidism
Copy link
Member

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 doobj.to_json() and also support[obj.to_json() for obj in objs].

@greyli
Copy link
ContributorAuthor

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.

@davidismdavidism added this to the2.2.0 milestoneJul 3, 2022
@davidism
Copy link
Member

davidism commentedJul 3, 2022
edited
Loading

Another potential confusion now that we support returning iterators/generators is that you're going to get very different results doingreturn ["a", "b", "c"] orreturn iter(["a", "b", "c"]).

@davidismdavidism merged commit559a845 intopallets:mainJul 3, 2022
@greyligreyli deleted the return-list branchJuly 3, 2022 04:49
@davidismdavidism added the json labelJul 3, 2022
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsJul 18, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

No reviews

Assignees

No one assigned

Labels

Projects

None yet

Milestone

2.2.0

Development

Successfully merging this pull request may close these issues.

2 participants

@greyli@davidism

Comments


[8]ページ先頭

©2009-2026 Movatter.jp