#24836: force_text doesn't force SimpleLazyObject into a string
-------------------------------+--------------------------------------
Reporter: riklaunim | Owner: nobody
Type: Uncategorized | Status: new
Component: Utilities | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by riklaunim):
* status: closed => new
* resolution: worksforme =>
Comment:
It does compare to string but it's not a string:
{{{
>>> from django.utils.functional import SimpleLazyObject
>>> from django.utils.encoding import force_text
>>> force_text(SimpleLazyObject(lambda: 'aaa'))
<SimpleLazyObject: 'aaa'>
}}}
so:
{{{
>>> force_text(SimpleLazyObject(lambda: 'aaa')) == 'aaa'
True
>>> import json
>>> json.dumps(force_text(SimpleLazyObject(lambda: 'aaa')))
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python3.4/json/__init__.py", line 230, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python3.4/json/encoder.py", line 186, in encode
return encode_basestring_ascii(o)
TypeError: first argument must be a string, not SimpleLazyObject
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24836#comment:2>
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/067.5c93be8d80748d26284e77b37a065465%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.