Opened 4 years ago

Closed 4 years ago

Last modified 4 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 Changed 4 years ago by David Nelson Adamec

Description: modified (diff)

comment:2 Changed 4 years ago by Tim Graham

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 Changed 4 years ago by Claude Paroz

Has patch: set

comment:4 Changed 4 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

Seems like a candidate for backport if you like.

comment:5 Changed 4 years ago by Claude Paroz <claude@…>

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 Changed 4 years ago by Claude Paroz <claude@…>

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