Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25295 closed Bug (fixed)

translation.override() context manager doesn't return to deactivated state when there's no activated language

Reported by: David Nelson Adamec Owned by: nobody
Component: Internationalization Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by David Nelson Adamec)

From a shell, I'm able to do the following:

In [1]: from django.utils import translation

In [2]: translation.get_language()

In [3]: with translation.override('fr'):
   ...:     pass
   ...:

In [4]: translation.get_language()
Out[4]: 'fr'

override usually reverts to the previous language upon leaving the context manager, so this behavior seems unexpected.

This is new in Django 1.8: before, get_language() returned the default language, so the default language would be activated after override finished. Now get_language() returns None when there is no active catalog, so override attempts to activate None, which has no effect.

Change History (6)

comment:1 by David Nelson Adamec, 9 years ago

Description: modified (diff)

comment:2 by Tim Graham, 9 years ago

Summary: override context manager does not return to deactivated statetranslation.override() context manager doesn't return to deactivated state when there's no activated language
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

I'm not a translation expert, but that does seem incorrect.

comment:3 by Claude Paroz, 9 years ago

Has patch: set

comment:4 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

Seems like a candidate for backport if you like.

comment:5 by Claude Paroz <claude@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 9324935c:

Fixed #25295 -- Restored 'no active translation' after language override

Thanks David Nelson Adamec for the report and Tim Graham for the review.

comment:6 by Claude Paroz <claude@…>, 9 years ago

In c177d069:

[1.8.x] Fixed #25295 -- Restored 'no active translation' after language override

Thanks David Nelson Adamec for the report and Tim Graham for the review.
Backport of 9324935c3 from master.

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