Skip to content
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

Error messages from ValidationError exception are not serialized correctly #1535

Open
JurajKavka opened this issue Dec 20, 2017 · 1 comment

Comments

@JurajKavka
Copy link

When ValidationError occurs, tastypie responds with an array of errors, that are not seriazlized to JSON correctly.

For example, this is the JSON repsponse, where the array with errors, is python representation of list() object, but not the valid JSON array of strings.

{
    "error": "[u'Ticket is already cancelled!']"
}

Expected result would be:

{
    "error": [
        "Ticket is already cancelled!"
    ]
}

Thank You.

sourya pushed a commit to sourya/django-tastypie that referenced this issue Oct 18, 2018
…cable

Signed-off-by: Sourya Vatsyayan <sourya@doselect.com>
@dizlv
Copy link

dizlv commented Apr 10, 2020

We experienced the same error when upgrading our TastyPie codebase to the newest versions: problem is that sanitize function has been introduced there and if you passed a list somewhere in your code, f.e. from form errors ValidationError(form.errors) then this sanitize would break everything. There's no easy way to fix this, since sanitize is implemented as a function.

Our approach was following: we had custom resource implemented, where we re-defined error_response method. Within that method we unpacked back message using html_decode & ast.literal_eval. The second option would be to use custom serializer (because error_response uses serializer methods underneath: serialized = self.serialize(request, errors, desired_format)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants