﻿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
22566	"ngettext_lazy returns ""unexpected type"" when one of the strings is also a lazy reference."	ygbo	nobody	"We have objects or dictionaries which store gettext_lazy strings,
If they are passed to ngettext_lazy we have a behaviour similar to https://code.djangoproject.com/ticket/19272 :

{{{
In [1]: from django.utils.translation import ngettext_lazy, gettext_lazy

In [2]: messages = {""singular"": gettext_lazy(""I'm alone""), ""plural"": gettext_lazy(""We are plenty"")}

In [3]: count = 1

In [4]: message = ngettext_lazy(messages['singular'], messages['plural'], count)

In [5]: 'alone' in message
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-a57c63f0b996> in <module>()
----> 1 'alone' in message

/home/yves/openstack/horizon/.venv/local/lib/python2.7/site-packages/django/utils/functional.pyc in __wrapper__(self, *args, **kw)
    127                     if t in self.__dispatch:
    128                         return self.__dispatch[t][funcname](res, *args, **kw)
--> 129                 raise TypeError(""Lazy object returned unexpected type."")
    130 
    131             if klass not in cls.__dispatch:

TypeError: Lazy object returned unexpected type.
}}}

I know we could use gettext_noop in this case, but we also use pgettext_lazy since there is no pgettext_noop and we really need a context in many cases. So this is why we use a lazy reference since the strings are stored on an object and some strings require a context.
whether we use gettext_lazy or pgettext_lazy, the error is the same after they go thru ngettext_lazy:

{{{
In [1]: from django.utils.translation import ngettext_lazy, pgettext_lazy

In [2]: messages = {""singular"": pgettext_lazy('context', ""I'm alone""), ""plural"": pgettext_lazy('context', ""We are plenty"")}

In [3]: count = 1

In [4]: message = ngettext_lazy(messages['singular'], messages['plural'], count)

In [5]: 'alone' in message
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-a57c63f0b996> in <module>()
----> 1 'alone' in message

/home/yves/openstack/horizon/.venv/local/lib/python2.7/site-packages/django/utils/functional.pyc in __wrapper__(self, *args, **kw)
    127                     if t in self.__dispatch:
    128                         return self.__dispatch[t][funcname](res, *args, **kw)
--> 129                 raise TypeError(""Lazy object returned unexpected type."")
    130 
    131             if klass not in cls.__dispatch:

TypeError: Lazy object returned unexpected type.
}}}
"	Uncategorized	closed	Uncategorized	1.6	Normal	wontfix			Unreviewed	0	0	0	0	0	0
