Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#24601 closed Bug (duplicate)

Template rendering breaks for number in management command due to translation.deactivate_all()

Reported by: stephanm Owned by: nobody
Component: Uncategorized Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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).

# -*- 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

Attachments (1)

website.zip (7.0 KB) - added by stephanm 4 years ago.

Download all attachments as: .zip

Change History (4)

Changed 4 years ago by stephanm

Attachment: website.zip added

comment:1 Changed 4 years ago by Tim Graham

Resolution: duplicate
Status: newclosed

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.

comment:2 Changed 4 years ago by stephanm

OK, if setting leave_locale_alone=True the error doesn't appear.

Will there be an 1.8.1 RC version to test?

Last edited 4 years ago by stephanm (previous) (diff)

comment:3 Changed 4 years ago by Tim Graham

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

Note: See TracTickets for help on using tickets.
Back to Top