Opened 5 years ago

Closed 5 years ago

#30723 closed Uncategorized (worksforme)

Lazy translations in field help cause JSON serialize errors

Reported by: Rob Lineberger Owned by: nobody
Component: contrib.auth Version: 2.2
Severity: Normal Keywords: json lazy serialization
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (1)

comment:1 by Claude Paroz, 5 years ago

Resolution: worksforme
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top