pylint-django icon indicating copy to clipboard operation
pylint-django copied to clipboard

Enforcing django settings import format

Open jarmstrong-atlassian opened this issue 1 year ago • 0 comments

According to django's docs, settings should be imported using from django.conf import settings and not your own settings file; see https://docs.djangoproject.com/en/5.1/topics/settings/#using-settings-in-python-code

I recently ran into a bug in our dev environment where a setting gave an ImportError using from myapp.mymodule import MY_SETTING, apparently because that setting was defined using environment variables (I'm guessing there may be some lazy loading behavior here that is bypassed by importing the setting directly).

Since pylint-django knows about the application's settings module via DJANGO_SETTINGS_MODULE, would it be possible to flag the incorrect style of import by looking for that module in import statements?

jarmstrong-atlassian avatar Sep 20 '24 16:09 jarmstrong-atlassian