}}}
This is because `gettext` returns an unicode string, but `gettext_lazy` is
defined as:
{{{
gettext_lazy = lazy(gettext, str)
}}}
{{{
>>> from django.utils.translation import gettext
>>> from django.utils.functional import lazy
>>> gettext("test")
u'test'
>>> gettext_lazy = lazy(gettext, unicode)
>>> gettext_lazy("test")
<django.utils.functional.__proxy__ object at 0x975cfec>
>>> _.upper()
u'TEST'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19272>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* severity: Normal => Release blocker
* cc: regression (added)
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* stage: Unreviewed => Accepted
Comment:
I'm not a fan of non-unicode gettext calls, so my suggestion would be to
replace it by `ugettext_lazy`. However this is a regression and
gettext_lazy should not transform the message to unicode on Python 2.
--
Ticket URL: <https://code.djangoproject.com/ticket/19272#comment:1>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/19272#comment:2>
* stage: Accepted => Ready for checkin
Comment:
The patch looks good to me. (I didn't apply it or run the tests.)
--
Ticket URL: <https://code.djangoproject.com/ticket/19272#comment:3>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"550ddc66b496473c8ee282c7ab6be5885a359d75"]:
{{{
#!CommitTicketReference repository=""
revision="550ddc66b496473c8ee282c7ab6be5885a359d75"
Fixed #19272 -- Fixed gettext_lazy returned type on Python 2
Thanks tyrion for the report.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19272#comment:4>
Comment (by Claude Paroz <claude@…>):
In [changeset:"ebafba50a418d4a444a067a3d35cea7f98a20158"]:
{{{
#!CommitTicketReference repository=""
revision="ebafba50a418d4a444a067a3d35cea7f98a20158"
[1.5.x] Fixed #19272 -- Fixed gettext_lazy returned type on Python 2
Thanks tyrion for the report.
Backport of 550ddc66b from master.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19272#comment:5>
Comment (by Preston Holmes <preston@…>):
In [changeset:"5566caeea85069d0560d95071d8a4592a91f6957"]:
{{{
#!CommitTicketReference repository=""
revision="5566caeea85069d0560d95071d8a4592a91f6957"
Fixed #19272 -- Fixed gettext_lazy returned type on Python 2
Thanks tyrion for the report.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19272#comment:6>
* status: closed => new
* resolution: fixed =>
Comment:
The issue still occurs with pgettext_lazy:
In [1]: from django.utils.translation import pgettext_lazy
In [2]: s = pgettext_lazy("a context", "foo bar") # using bytestring
In [3]: s.upper()
/usr/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py:53:
RuntimeWarning: SQLite received a naive datetime (2014-04-29
12:18:28.940685) while time zone support is active.
RuntimeWarning)
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
/usr/lib/python2.7/dist-packages/django/core/management/commands/shell.pyc
in <module>()
----> 1 s.upper()
/usr/lib/python2.7/dist-packages/django/utils/functional.pyc in
__wrapper__(self, *args, **kw)
121 if t in self.__dispatch:
122 return self.__dispatch[t][funcname](res,
*args, **kw)
--> 123 raise TypeError("Lazy object returned unexpected
type.")
124
125 if klass not in cls.__dispatch:
TypeError: Lazy object returned unexpected type.
In [4]: s = pgettext_lazy("a context", u"foo bar") # using unicode string
In [5]: s.upper()
Out[5]: u'FOO BAR'
--
Ticket URL: <https://code.djangoproject.com/ticket/19272#comment:7>
* status: new => closed
* resolution: => fixed
Comment:
Please don't re-open a ticket that has been closed and fixed (the reported
issue here is about `gettext_lazy`).
Open a new ticket that refers to this one for the `pgettext_lazy` issue by
making sure to use formatting (wrap your code between `{{{` and `}}}`).
You can go ahead and mark the ticket as an accepted bug from the beginning
since I managed to reproduce with you provided test case.
--
Ticket URL: <https://code.djangoproject.com/ticket/19272#comment:8>
Comment (by ygbo):
Ok thanks,
I just logged https://code.djangoproject.com/ticket/22565
--
Ticket URL: <https://code.djangoproject.com/ticket/19272#comment:9>