From 0638b4e23dbabdcf7d7a6f2a2d5b95b980dece78 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 3 Aug 2022 15:45:09 +0200 Subject: [PATCH] Fixed #33888 -- Fixed get_select2_language() crash with no language activated. Regression in 3079133c73f3b8b0e929673b06b62dce1f54be71. --- django/contrib/admin/widgets.py | 2 +- docs/releases/4.1.1.txt | 3 +++ tests/admin_widgets/test_autocomplete_widget.py | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index d48500e356..c7d5db209e 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -456,7 +456,7 @@ SELECT2_TRANSLATIONS.update({"zh-hans": "zh-CN", "zh-hant": "zh-TW"}) def get_select2_language(): lang_code = get_language() supported_code = SELECT2_TRANSLATIONS.get(lang_code) - if supported_code is None: + if supported_code is None and lang_code is not None: # If 'zh-hant-tw' is not supported, try subsequent language codes i.e. # 'zh-hant' and 'zh'. i = None diff --git a/docs/releases/4.1.1.txt b/docs/releases/4.1.1.txt index 67b0898e0e..2d705f6a99 100644 --- a/docs/releases/4.1.1.txt +++ b/docs/releases/4.1.1.txt @@ -11,3 +11,6 @@ Bugfixes * Reallowed, following a regression in Django 4.1, using ``GeoIP2()`` when GEOS is not installed (:ticket:`33886`). + +* Fixed a regression in Django 4.1 that caused a crash of admin's autocomplete + widgets when translations are deactivated (:ticket:`33888`). diff --git a/tests/admin_widgets/test_autocomplete_widget.py b/tests/admin_widgets/test_autocomplete_widget.py index e2827b9147..ec0823a0da 100644 --- a/tests/admin_widgets/test_autocomplete_widget.py +++ b/tests/admin_widgets/test_autocomplete_widget.py @@ -179,6 +179,7 @@ class AutocompleteMixinTests(TestCase): ("sr-cyrl", "sr-Cyrl"), ("zh-hans", "zh-CN"), ("zh-hant", "zh-TW"), + (None, None), ) for lang, select_lang in languages: with self.subTest(lang=lang):