Skip to content

Better error message when view return type is not supported #3214

Closed

Description

@davidism

One of the most common errors/questions on Stack Overflow is some variant of "what does 'dict object is not callable' mean, how do I return JSON?" Now that #3111 is merged, returning dict from a view produces a JSON response. However, there are still plenty of other types that will produce that error, such as returning a bool, or a User object, or a list of rows from a database query.

Flask.make_response should check whether an otherwise unhandled value is a BaseResponse subclass or a callable before treating it as such. Then it can raise a more helpful error.

Activity

  1. added
    save-for-sprintPlease don't pick this unless you're participating in an official sprint.
    on May 24, 2019
  2. added 3 commits that reference this issue on May 31, 2019
    5336fea
    f2d88b3
    8bb7185
  3. jaos commented on Jul 8, 2019

    @jaos

    What is the utility of using force_type on Response subclasses then? I had a custom response class that would call special internal serialization on subclasses of my application model objects within force_type. Now force_type never gets called.

  4. davidism commented on Jul 8, 2019

    @davidism
    MemberAuthor

    Please open a new issue if you have a new issue. Be sure to include a minimal reproducible example.

  5. jaos commented on Jul 8, 2019

    @jaos

    Thanks, will do.

  6. locked as resolved and limited conversation to collaborators on Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    save-for-sprintPlease don't pick this unless you're participating in an official sprint.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions