[Django] #30723: Lazy translations in field help cause JSON serialize errors

5 views
Skip to first unread message

Django

unread,
Aug 21, 2019, 4:30:05 PM8/21/19
to django-...@googlegroups.com
#30723: Lazy translations in field help cause JSON serialize errors
-------------------------------------+-------------------------------------
Reporter: Rob | Owner: nobody
Lineberger |
Type: | Status: new
Uncategorized |
Component: | Version: 2.2
contrib.auth | Keywords: json lazy
Severity: Normal | serialization
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Attempting to json.dumps() the result of apps.get_models() leads to a
TypeError:

{{{

TypeError at /uploader/select-models/

'Designates whether this user should be treated as active. Unselect this
instead of deleting accounts.' is not JSON serializable
}}}

That is because "Designates whether this user should be treated as active.
...." is not a string, but the converted representation of a
django.utils.functional.lazy.<locals>__proxy__ object. That is not JSON
serializable.

Debugging this is onerous because in all respects the help text looks and
acts like a string.

--
Ticket URL: <https://code.djangoproject.com/ticket/30723>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 21, 2019, 5:05:25 PM8/21/19
to django-...@googlegroups.com
#30723: Lazy translations in field help cause JSON serialize errors
-------------------------------------+-------------------------------------
Reporter: Rob Lineberger | Owner: nobody
Type: Uncategorized | Status: closed
Component: contrib.auth | Version: 2.2
Severity: Normal | Resolution:
| worksforme
Keywords: json lazy | Triage Stage:
serialization | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* status: new => closed
* resolution: => worksforme


Comment:

Django has a special JSON encoder to dumps typical Django data:
https://docs.djangoproject.com/en/2.2/topics/serialization/#djangojsonencoder
I don't see what we could do to prevent your bad debugging session, but if
you have ideas, feel free to suggest them.

--
Ticket URL: <https://code.djangoproject.com/ticket/30723#comment:1>

Reply all
Reply to author
Forward
0 new messages