1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[5.0.x] Fixed #35627 -- Raised a LookupError rather than an unhandled ValueError in get_supported_language_variant().

LocaleMiddleware didn't handle the ValueError raised by
get_supported_language_variant() when language codes were
over 500 characters.

Regression in 9e9792228a.

Backport of 0e94f292cd from main.
This commit is contained in:
Lorenzo Peña
2024-07-23 12:06:29 +02:00
committed by Sarah Boyce
parent 41d8ef18ac
commit e18601273a
6 changed files with 31 additions and 7 deletions

View File

@@ -517,7 +517,7 @@ def get_supported_language_variant(lang_code, strict=False):
# There is a generic variant under the maximum length accepted length.
lang_code = lang_code[:index]
else:
raise ValueError("'lang_code' exceeds the maximum accepted length")
raise LookupError(lang_code)
# If 'zh-hant-tw' is not supported, try special fallback or subsequent
# language codes i.e. 'zh-hant' and 'zh'.
possible_lang_codes = [lang_code]