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


In django 1.8 an old management command does not work anymore.

It stumbles over the number, because in django/core/management/ 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 import BaseCommand
from django.template import Context, Template
txt = " {{number}} {{text}}"

class Command(BaseCommand):

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

To reproduce please unzip
and run:

website> myapp_test

You will get a lengthy output whichs ends with:

File "D:\Programme\python27\lib\site-packages\django\utils\", line 125, in wrapper
    result = user_function(*args, **kwds)
  File "D:\Programme\python27\lib\site-packages\django\utils\translation\", line 409, in check_for_language
    if not
TypeError: expected string or buffer

Attachments (1) (7.0 KB) - added by stephanm 4 years ago.

Download all attachments as: .zip

Change History (4)

Changed 4 years ago by stephanm

Attachment: 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