Skip to content

Enforcing django settings import format #434

Open
@jarmstrong-atlassian

Description

@jarmstrong-atlassian

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions