﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32272	gettext_lazy inconsistent error when nested	John Bazik	Ahmed Nassar	"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."	Bug	assigned	Internationalization	3.1	Normal			Claude Paroz	Accepted	1	0	1	1	0	0
