fix: i18n User.language_code is optional

user.language_code is Optional and may raise an exception

#870
This commit is contained in:
Oleg A 2022-03-25 11:56:58 +03:00
parent 79588b7c5d
commit d633cc17b7
No known key found for this signature in database
GPG key ID: 5FE046817A9657C5

View file

@ -118,7 +118,7 @@ class SimpleI18nMiddleware(I18nMiddleware):
)
event_from_user: Optional[User] = data.get("event_from_user", None)
if event_from_user is None:
if event_from_user is None or event_from_user.language_code is None:
return self.i18n.default_locale
try:
locale = Locale.parse(event_from_user.language_code, sep="-")