[Django] #22900: ugettext_lazy with arguments causes RuntimeError

24 views
Skip to first unread message

Django

unread,
Jun 25, 2014, 5:58:26 AM6/25/14
to django-...@googlegroups.com
#22900: ugettext_lazy with arguments causes RuntimeError
-------------------------------+------------------------
Reporter: Karmux | Owner: nobody
Type: Uncategorized | Status: new
Component: Translations | Version: 1.7-beta-2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------
If I use arguments with translations I get RuntimeError.

{{{
help_text=_('e.g. %(foo)s or %(bar)s') % {
'foo': 'footxt', 'bar': 'bartxt'})
}}}

This code causes following error:

{{{
Traceback (most recent call last):
File "./manage", line 13, in <module>
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line
21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py",
line 106, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py",
line 190, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in
import_module
__import__(name)
File "/home/karmo/Dev/project/api/models.py", line 205, in <module>
class Test(Model):
File "/home/karmo/Dev/project/api/models.py", line 222, in Test
'foo': 'footxt', 'bar': 'bartxt'})
File "/usr/local/lib/python2.7/dist-
packages/django/utils/functional.py", line 179, in __mod__
return six.text_type(self) % rhs
File "/usr/local/lib/python2.7/dist-
packages/django/utils/functional.py", line 144, in __text_cast
return func(*self.__args, **self.__kw)
File "/usr/local/lib/python2.7/dist-
packages/django/utils/translation/__init__.py", line 83, in ugettext
return _trans.ugettext(message)
File "/usr/local/lib/python2.7/dist-
packages/django/utils/translation/trans_real.py", line 317, in ugettext
return do_translate(message, 'ugettext')
File "/usr/local/lib/python2.7/dist-
packages/django/utils/translation/trans_real.py", line 298, in
do_translate
_default = translation(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.7/dist-
packages/django/utils/translation/trans_real.py", line 201, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.7/dist-
packages/django/utils/translation/trans_real.py", line 184, in _fetch
for app_config in reversed(list(apps.get_app_configs())):
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py",
line 125, in get_app_configs
self.check_ready()
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py",
line 119, in check_ready
raise RuntimeError("App registry isn't ready yet.")
RuntimeError: App registry isn't ready yet.
}}}

Seems it uses non-lazy ugettext in django/utils/translation/__init__.py.

If I remove dictionary from the end of _() then this error disappears.

I'm using Django 1.7b4.

--
Ticket URL: <https://code.djangoproject.com/ticket/22900>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 25, 2014, 9:15:47 AM6/25/14
to django-...@googlegroups.com
#22900: ugettext_lazy with arguments causes RuntimeError
-------------------------------+--------------------------------------

Reporter: Karmux | Owner: nobody
Type: Uncategorized | Status: new
Component: Translations | Version: 1.7-beta-2
Severity: Normal | Resolution:
Keywords: app-loading | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by aaugustin):

* keywords: => app-loading
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/22900#comment:1>

Django

unread,
Jun 25, 2014, 9:39:50 AM6/25/14
to django-...@googlegroups.com
#22900: ugettext_lazy with arguments causes RuntimeError
-------------------------------+--------------------------------------

Reporter: Karmux | Owner: nobody
Type: Uncategorized | Status: new
Component: Translations | Version: 1.7-beta-2
Severity: Normal | Resolution:
Keywords: app-loading | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by timo):

Note this will raise a different message on master due to
9618d68b345fe69c787f8426b07e920e647e05f3.

--
Ticket URL: <https://code.djangoproject.com/ticket/22900#comment:2>

Django

unread,
Jun 25, 2014, 2:02:58 PM6/25/14
to django-...@googlegroups.com
#22900: ugettext_lazy with arguments causes RuntimeError
-------------------------------------+-------------------------------------
Reporter: Karmux | Owner: nobody
Type: New feature | Status: new
Component: | Version:
Internationalization | 1.7-beta-2
Severity: Normal | Resolution:
Keywords: app-loading | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* type: Uncategorized => New feature
* component: Translations => Internationalization
* stage: Unreviewed => Accepted


Comment:

This is expected behavior with the current implementation, the `%` (mod)
operator on lazy strings does produce the final string.
We might experiment with delaying the translation in this case and find
out (a) if it's possible and (b) if the behavior change is not too much
backwards incompatible.
At the very least, we could improve the documentation.

--
Ticket URL: <https://code.djangoproject.com/ticket/22900#comment:3>

Django

unread,
Jun 29, 2014, 3:09:18 PM6/29/14
to django-...@googlegroups.com
#22900: ugettext_lazy with arguments causes RuntimeError
-------------------------------------+-------------------------------------
Reporter: Karmux | Owner: nobody

Type: New feature | Status: new
Component: | Version:
Internationalization | 1.7-beta-2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* keywords: app-loading =>


Comment:

This code was silently doing the wrong thing in Django < 1.7. Now it's
failing loudly. That's an intended and documented consequence of the app-
loading refactor.

--
Ticket URL: <https://code.djangoproject.com/ticket/22900#comment:4>

Django

unread,
Dec 18, 2014, 4:45:04 PM12/18/14
to django-...@googlegroups.com
#22900: ugettext_lazy with arguments causes RuntimeError
--------------------------------------+------------------------------------
Reporter: Karmux | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.7

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* type: New feature => Cleanup/optimization
* version: 1.7-beta-2 => 1.7
* component: Internationalization => Documentation


--
Ticket URL: <https://code.djangoproject.com/ticket/22900#comment:5>

Django

unread,
Aug 18, 2016, 8:57:40 PM8/18/16
to django-...@googlegroups.com
#22900: ugettext_lazy with arguments causes RuntimeError
--------------------------------------+------------------------------------
Reporter: Karmux | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by timgraham):

Claude, do you think we need a documentation enhancement now that we have
the "The translation infrastructure cannot be initialized before the apps
registry is ready. Check that you don't make non-lazy gettext calls at
import time." error message? If so, maybe you could suggest a location for
that documentation and retitle the ticket to make it more suitable for
beginners to contribute?

--
Ticket URL: <https://code.djangoproject.com/ticket/22900#comment:6>

Django

unread,
Aug 19, 2016, 4:27:36 AM8/19/16
to django-...@googlegroups.com
#22900: ugettext_lazy with arguments causes RuntimeError
--------------------------------------+------------------------------------
Reporter: Karmux | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by claudep):

I think the section in
https://docs.djangoproject.com/en/1.10/topics/i18n/translation/#working-
with-lazy-translation-objects will need to be updated, particularly after
`format_lazy` will be added (#26866 / #27067).

--
Ticket URL: <https://code.djangoproject.com/ticket/22900#comment:7>

Django

unread,
Jun 9, 2018, 5:15:47 PM6/9/18
to django-...@googlegroups.com
#22900: ugettext_lazy with arguments causes RuntimeError
--------------------------------------+------------------------------------
Reporter: Karmo Rosental | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.7
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Claude Paroz):

* status: new => closed
* resolution: => fixed


Comment:

I guess that the `format_lazy` addition in docs should now be sufficient.

--
Ticket URL: <https://code.djangoproject.com/ticket/22900#comment:8>

Reply all
Reply to author
Forward
0 new messages