Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#27382 closed Bug (fixed)

Document that ugettext_lazy() result can't be used with arbitrary Python code

Reported by: Mike Edmunds Owned by: nobody
Component: Documentation Version: 1.10
Severity: Normal Keywords: ugettext_lazy
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The documentation currently states that:

The result of a ugettext_lazy() call can be used wherever you would use a unicode string (an object with type unicode) in Python.

However, the result of ugettext_lazy() does not pass isinstance(lazy_obj, unicode). Because instance checks are commonly used to detect text strings, the lazy objects are incompatible with some Python standard library code and other popular Python packages (such as requests).

Proposed doc patch clarifies that ugettext_lazy() can be used with other Django code, but that it should generally be converted to text before passing to arbitrary, non-Django Python code.

Discussion and examples on django-dev: https://groups.google.com/forum/#!topic/django-developers/eFsGf1ZrG7c

Change History (4)

comment:1 by Mike Edmunds, 8 years ago

Has patch: set

Doc change: https://github.com/django/django/pull/7430

(Aside: I did also explore changing ugettext_lazy() to test as an instance of text_type. It's not totally infeasible, but would probably cause at least as many problems as it would solve. https://github.com/medmunds/django/pull/1 if you're curious.)

comment:2 by Moritz Sichert, 8 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: newclosed

In d3708aeb:

Fixed #27382 -- Doc'd that ugettext_lazy() should be converted to text for non-Django code.

comment:4 by Tim Graham <timograham@…>, 7 years ago

In 59001ca:

[1.10.x] Fixed #27382 -- Doc'd that ugettext_lazy() should be converted to text for non-Django code.

Backport of d3708aeb26032911897e213a300c8b8ea5c5a345 from master

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