Kaydet (Commit) 9324935c authored tarafından Claude Paroz's avatar Claude Paroz

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

Thanks David Nelson Adamec for the report and Tim Graham for the review.
üst 4ce433e8
...@@ -164,7 +164,9 @@ class override(ContextDecorator): ...@@ -164,7 +164,9 @@ class override(ContextDecorator):
deactivate_all() deactivate_all()
def __exit__(self, exc_type, exc_value, traceback): def __exit__(self, exc_type, exc_value, traceback):
if self.deactivate: if self.old_language is None:
deactivate_all()
elif self.deactivate:
deactivate() deactivate()
else: else:
activate(self.old_language) activate(self.old_language)
......
...@@ -13,3 +13,5 @@ Bugfixes ...@@ -13,3 +13,5 @@ Bugfixes
field that is both a foreign and primary key (:ticket:`24951`). field that is both a foreign and primary key (:ticket:`24951`).
* Fixed a migrations crash with ``GenericForeignKey`` (:ticket:`25040`). * Fixed a migrations crash with ``GenericForeignKey`` (:ticket:`25040`).
* Made ``translation.override()`` clear the overridden language when a
translation isn't initially active (:ticket:`25295`).
...@@ -76,6 +76,9 @@ class TranslationTests(SimpleTestCase): ...@@ -76,6 +76,9 @@ class TranslationTests(SimpleTestCase):
self.assertEqual(get_language(), 'de') self.assertEqual(get_language(), 'de')
with translation.override(None): with translation.override(None):
self.assertEqual(get_language(), None) self.assertEqual(get_language(), None)
with translation.override('pl'):
pass
self.assertEqual(get_language(), None)
self.assertEqual(get_language(), 'de') self.assertEqual(get_language(), 'de')
finally: finally:
deactivate() deactivate()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment