You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When editing the Django project's settings.py, when calling pylint we get a Django error message saying the config was not properly set, even though we correctly pass the flag --django-settings-module.
The problem is particular to modifications to settings.py, since modifications to any other file are still correctly processed by pylint.
Steps to reproduce:
Install pylint and pylint-django
Open a Django app (I cannot supply code for mine since it's closed source)
Edit the settings app; in our tests, we did
INSTALLED_APPS= [
...
"django_extensions",
]
(installing django-extensions is not required though)
4. Run pylint with pylint-django
Traceback (most recent call last):
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/pylint_django/checkers/foreign_key_strings.py", line 92, in open
django.setup()
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/django/conf/__init__.py", line 82, in __getattr__
self._setup(name)
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/django/conf/__init__.py", line 63, 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.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/pylint_django/checkers/foreign_key_strings.py", line 120, in open
settings.configure(Settings(self.config.django_settings_module))
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/django/conf/__init__.py", line 170, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'scala_alocacao'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/bin/pylint", line 8, in <module>
sys.exit(run_pylint())
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/pylint/__init__.py", line 22, in run_pylint
PylintRun(argv or sys.argv[1:])
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/pylint/lint/run.py", line 358, in __init__
linter.check(args)
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1073, in check
self._check_files(
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1108, in _check_files
with self._astroid_module_checker() as check_astroid_module:
File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1236, in _astroid_module_checker
checker.open()
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/pylint_django/checkers/foreign_key_strings.py", line 125, in open
self.add_message(
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/pylint/checkers/base_checker.py", line 112, in add_message
self.linter.add_message(
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1631, in add_message
self._add_one_message(
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1564, in _add_one_message
self.stats.increase_single_module_message_count(
File "/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/venv/lib/python3.10/site-packages/pylint/utils/linterstats.py", line 300, in increase_single_module_message_count
self.by_module[modname][type_name] += increase
KeyError: '/mnt/ubuntu_home/tomaz/git/Estágio/Scala/scala_alocacao/pylintrc'
We stumbled upon this bug when running pylint through pre-commit; in that case, we worked around this issue by running git commit --no-verify when changing settings.py, in case anyone else goes through something similar.
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.
fixespylint-dev#309 (pylint-dev#309 (comment))
fixespylint-dev#325
might relate to pylint-dev#362
When editing the Django project's
settings.py
, when callingpylint
we get a Django error message saying the config was not properly set, even though we correctly pass the flag--django-settings-module
.The problem is particular to modifications to
settings.py
, since modifications to any other file are still correctly processed bypylint
.Steps to reproduce:
pylint
andpylint-django
(installing
django-extensions
is not required though)4. Run
pylint
withpylint-django
Traceback
System configuration
pip freeze
pylintrc
The text was updated successfully, but these errors were encountered: