[Django] #24601: Template rendering breaks for number in management command due to translation.deactivate_all()

20 views
Skip to first unread message

Django

unread,
Apr 8, 2015, 5:46:48 AM4/8/15
to django-...@googlegroups.com
#24601: Template rendering breaks for number in management command due to
translation.deactivate_all()
-------------------------------+--------------------
Reporter: stephanm | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
In django 1.8 an old management command does not work anymore.

It stumbles over the number, because in
{{{django/core/management/base.py}}} on line 403
{{{translation.deactivate_all()}}} is called, and later
{{{ _active.value = gettext_module.NullTranslations() }}}
is set.
At least, I found a workaround by setting an explicit language.
Here is the test class to reproduce (if you set: {{{ ACTIVATE_WORKAROUND =
True}}} it will work).
{{{#!py
# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand
from django.template import Context, Template
txt = " {{number}} {{text}}"

class Command(BaseCommand):

def handle(self, *args, **options):
ACTIVATE_WORKAROUND = False
if ACTIVATE_WORKAROUND:
from django.utils import translation
translation.activate("de")
t = Template(txt)
par = {'number': 9009, 'text': 'text', }
c = Context(par)
s = t.render(c)
print s

}}}
To reproduce please unzip website.zip
and run:
{{{
website> manage.py myapp_test
}}}

You will get a lengthy output whichs ends with:
{{{
...
File "D:\Programme\python27\lib\site-packages\django\utils\lru_cache.py",
line 125, in wrapper
result = user_function(*args, **kwds)
File "D:\Programme\python27\lib\site-
packages\django\utils\translation\trans_real.py", line 409, in
check_for_language
if not language_code_re.search(lang_code):
TypeError: expected string or buffer
}}}

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

Django

unread,
Apr 8, 2015, 5:47:15 AM4/8/15
to django-...@googlegroups.com
#24601: Template rendering breaks for number in management command due to
translation.deactivate_all()
---------------------------+----------------------------

Reporter: stephanm | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------+----------------------------
Changes (by stephanm):

* Attachment "website.zip" added.

Django

unread,
Apr 8, 2015, 9:13:29 AM4/8/15
to django-...@googlegroups.com
#24601: Template rendering breaks for number in management command due to
translation.deactivate_all()
-------------------------------+--------------------------------------
Reporter: stephanm | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 1.8
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* status: new => closed
* needs_docs: => 0
* resolution: => duplicate
* needs_tests: => 0
* needs_better_patch: => 0


Comment:

It seems this will be fixed in 1.8.1 by #24569.

Also note this related item in the 1.8 release notes:
{{{
* When the leave_locale_alone attribute is False, translations are now
deactivated instead of forcing the “en-us” locale.
}}}

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

Django

unread,
Apr 8, 2015, 11:26:43 AM4/8/15
to django-...@googlegroups.com
#24601: Template rendering breaks for number in management command due to
translation.deactivate_all()
-------------------------------+--------------------------------------
Reporter: stephanm | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 1.8
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Unreviewed

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

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

Comment (by stephanm):

OK if setting {{{leave_locale_alone=True}}} the error dowsnt appear.

Will there be an 1.8.1 RC version to test?

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

Django

unread,
Apr 8, 2015, 12:42:32 PM4/8/15
to django-...@googlegroups.com
#24601: Template rendering breaks for number in management command due to
translation.deactivate_all()
-------------------------------+--------------------------------------
Reporter: stephanm | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 1.8
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Unreviewed

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

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

Comment (by timgraham):

There won't be a 1.8.1 RC, but you can test with the stable/1.8.x branch
now.

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

Reply all
Reply to author
Forward
0 new messages