#32272: gettext_lazy inconsistent error when nested
--------------------------------------+------------------------
               Reporter:  John Bazik  |          Owner:  nobody
                   Type:  Bug         |         Status:  new
              Component:  Utilities   |        Version:  3.1
               Severity:  Normal      |       Keywords:
           Triage Stage:  Unreviewed  |      Has patch:  0
    Needs documentation:  0           |    Needs tests:  0
Patch needs improvement:  0           |  Easy pickings:  0
                  UI/UX:  0           |
--------------------------------------+------------------------
 When gettext_lazy is called with a lazy object, it returns a nested lazy
 object which has inconsistent behavior, depending on whether USE_I18N is
 set or not.


 {{{
 >>> from django import __version__
 >>> print(__version__)
 3.1
 >>> from django.utils.functional import lazy
 >>> from django.utils.translation.trans_real import gettext as
 gettext_real
 >>> from django.utils.translation.trans_null import gettext as
 gettext_noop
 >>> gettext_lazy_real = lazy(gettext_real, str)
 >>> gettext_lazy_noop = lazy(gettext_noop, str)
 >>> r1 = gettext_lazy_real('Real')
 >>> r2 = gettext_lazy_real(r1)
 >>> n1 = gettext_lazy_noop('Noop')
 >>> n2 = gettext_lazy_noop(n1)
 >>> print(str(r1))
 Real
 >>> print(str(r2))
 Real
 >>> print(str(n1))
 Noop
 >>> print(str(n2))
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
 TypeError: __str__ returned non-string (type __proxy__)
 }}}

 I discovered this problem while working with version 2.2.

 I've run across this twice now.  The first time, I created a pull request
 for another project to avoid the nesting.  However, now that I've seen it
 again, I think that because it works in the case of USE_I18N=True, it's
 easy for developers to miss the problem, especially so since testing
 USE_I18N has some quirks.  Here's my pull request:

 https://github.com/django-cms/django-cms/pull/6896

 I think the best fix would be to disallow nesting by simply returning
 already-nested objects, but I'm not sure of all the subtleties in that
 code.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32272>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.2d748f132a631f91e51b0418ce1c06d4%40djangoproject.com.

Reply via email to