Skip to content

ImproperlyConfigured exception about LOGGING_CONFIG #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sylvain1811 opened this issue Feb 3, 2021 · 3 comments · May be fixed by #363
Open

ImproperlyConfigured exception about LOGGING_CONFIG #309

sylvain1811 opened this issue Feb 3, 2021 · 3 comments · May be fixed by #363

Comments

@sylvain1811
Copy link

I'm getting the following error when I run pylint on my project using pylint-django==2.4.2:

> poetry run pylint --django-settings-module=myapp.settings myapp
Traceback (most recent call last):
  File "/home/sylvain/LNS/mylns-api/.venv/lib/python3.7/site-packages/pylint_django/checkers/foreign_key_strings.py", line 90, in open
    django.setup()
  File "/home/sylvain/LNS/mylns-api/.venv/lib/python3.7/site-packages/django/__init__.py", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/home/sylvain/LNS/mylns-api/.venv/lib/python3.7/site-packages/django/conf/__init__.py", line 82, in __getattr__
    self._setup(name)
  File "/home/sylvain/LNS/mylns-api/.venv/lib/python3.7/site-packages/django/conf/__init__.py", line 67, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

I have a .pylintrc file loading pylint-django, and I think I correctly use --django-settings-module=myapp.settings command line argument. I also tried to add django-settings-module=myapp.settings in my .pylintrc, still failed.

I've read comments on #306, especially this one and I think it's an issue of pylint-django itself and not about configuration, so I create this issue.

Workaround: downgrade to 2.3.0

@sylvain1811 sylvain1811 changed the title ImproperlyConfigured exception about LOGGING_CONFIG ImproperlyConfigured exception about LOGGING_CONFIG Feb 3, 2021
@dragonpaw
Copy link

dragonpaw commented Apr 10, 2021

For what it's worth, I'm having this happen too, but only if I use pylint's --django-settings-module. If I set DJANGO_SETTINGS_MODULE first, it goes away. And I looked at #306 and I'm pretty sure he was having the same issue.

# pylint --load-plugins pylint_django --django-settings-module=config.settings.base ticketing
Running insecure for localhost.
Traceback (most recent call last):
  File "/Users/ash/.pyenv/versions/django/lib/python3.9/site-packages/pylint_django/checkers/foreign_key_strings.py", line 90, in open
    django.setup()
  File "/Users/ash/.pyenv/versions/django/lib/python3.9/site-packages/django/__init__.py", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/Users/ash/.pyenv/versions/django/lib/python3.9/site-packages/django/conf/__init__.py", line 79, in __getattr__
    self._setup(name)
  File "/Users/ash/.pyenv/versions/django/lib/python3.9/site-packages/django/conf/__init__.py", line 60, in _setup
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
...

But...

# DJANGO_SETTINGS_MODULE=config.settings.base pylint --load-plugins pylint_django ticketing
************* Module ticketing
ticketing/__init__.py:4:19: R1728: Consider using a generator instead 'tuple(int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.'))' (consider-using-generator)
...

So it's not that my Django config is broken, it's not. The app runs fine. It's something specific with how init is handled with the cli option vs. the environment variable. Hope this helps you track it down...

@Routhinator
Copy link

Routhinator commented May 28, 2021

Confirmed, downgrading to 2.3.0 fixed this for me as well.

Using the ENV variable instead of the parameter as @dragonpaw did; did not

@twig
Copy link

twig commented Nov 4, 2021

Cheers @Routhinator , downgrading saved my sanity

TheAfroOfDoom added a commit to TheAfroOfDoom/pylint-django that referenced this issue Jun 4, 2022
Both `DJANGO_SETTINGS_MODULE` and `DJANGO_CONFIGURATION` are required for `django.configurations.importer` to install, else it throws an exception.
If the `importer` is not installed, `django.setup()` fails on `configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)` when trying to access uninitialized settings.

fixes pylint-dev#309 (pylint-dev#309 (comment))
fixes pylint-dev#325
might relate to pylint-dev#362
@TheAfroOfDoom TheAfroOfDoom linked a pull request Jun 4, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants