[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.
This commit is contained in:
Claude Paroz 2015-08-21 14:09:29 +02:00
parent 181528726e
commit c177d0690e
3 changed files with 8 additions and 1 deletions

View File

@ -163,7 +163,9 @@ class override(ContextDecorator):
deactivate_all()
def __exit__(self, exc_type, exc_value, traceback):
if self.deactivate:
if self.old_language is None:
deactivate_all()
elif self.deactivate:
deactivate()
else:
activate(self.old_language)

View File

@ -13,3 +13,5 @@ Bugfixes
field that is both a foreign and primary key (:ticket:`24951`).
* Fixed a migrations crash with ``GenericForeignKey`` (:ticket:`25040`).
* Made ``translation.override()`` clear the overridden language when a
translation isn't initially active (:ticket:`25295`).

View File

@ -74,6 +74,9 @@ class TranslationTests(TestCase):
self.assertEqual(get_language(), 'de')
with translation.override(None):
self.assertEqual(get_language(), None)
with translation.override('pl'):
pass
self.assertEqual(get_language(), None)
self.assertEqual(get_language(), 'de')
finally:
deactivate()