sbordeyne / fastapi_rss

A simple plug-in to FastAPI, that allows easy RSS feed generation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`RSSFeed` model ImportError when locale not set

sneakers-the-rat opened this issue · comments

locale.getdefaultlocale() (which is deprecated) and locale.getlocale() can return None if language cannot be determined: https://docs.python.org/3/library/locale.html#locale.getdefaultlocale

Since the default in the model calls the function directly (rather than using default_factory), the model can't be imported at all:

language: str = get_locale_code()

due to a predictable AttributeError: NoneType object has no attribute lower thrown here:

return locale.getdefaultlocale()[0].lower()

to fix:

  • use default_factory so the model can be imported and patched if needed
  • make language optional, and check for None type in get_locale_code

This has been deployed on PyPI