#26110: Admin form escapes postgres JSONField on ValidationError
-------------------------------+------------------------------
Reporter: outime | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.9
Severity: Normal | Keywords: jsonfield, admin
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------
To reproduce this bug, let's assume we have this model:
{{{#!python
class TestModel(models.Model):
test_url = models.URLField() # I've chosen URLField as an example but
the specific type of field is irrelevant for this issue
json_field = JSONField(default={})
}}}
The model is added to the admin site the standard way
(`admin.site.register()`) so that we can add content easily. Now, if you
go and submit the following:
`test_url` → `test`
`json_field` → `{"hello": "hola"}`
It'll trigger an expected `ValidationError` since it's not a valid URL.
When the form is rendered and presented back to the user, the `test_url`
will show the incorrect URL while the `json_field` will look like this:
`"{\"hello\": \"hola\"}"`. If the user corrects the `test_url` and submits
the form again, the `json_field` that's being stored in the DB will be the
escaped one.
I can't say if this only happens with admin forms or any form (e.g. model
forms) since I have no time to run proper tests, but I hope this is enough
to track down the issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/26110>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.799bd2b7e317ef41a08c5c4def819fcf%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.