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

Issue using commandline flag with pylint

Open slorg1 opened this issue 3 years ago • 0 comments

I get a crash now when using the commandline flags.

Fix https://github.com/PyCQA/pylint-django/issues/385

The issue is that creating the Settings objects already configures the settings.

See the symptom:

$ pylint --load-plugins=pylint_django --enable=W0611 --disable=bad-continuation,invalid-name,no-self-argument,E0211,C0116,C0115,C0114 --max-line-length=110 --django-settings-module=heypluto.settings.local **/*.py
************* Module Command line
Command line:1:0: R0022: Useless option value for '--disable', 'bad-continuation' was removed from pylint, see https://github.com/PyCQA/pylint/pull/3571. (useless-option-value)
Traceback (most recent call last):
  File "/home/dev/.virtualenvs/pluto-chat/lib/python3.8/site-packages/pylint_django/checkers/foreign_key_strings.py", line 92, in open
    django.setup()
  File "/home/dev/.virtualenvs/pluto-chat/lib/python3.8/site-packages/django/__init__.py", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/home/dev/.virtualenvs/pluto-chat/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__
    self._setup(name)
  File "/home/dev/.virtualenvs/pluto-chat/lib/python3.8/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 "/home/dev/.virtualenvs/pluto-chat/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/home/dev/.virtualenvs/pluto-chat/lib/python3.8/site-packages/pylint/__init__.py", line 25, in run_pylint
    PylintRun(argv or sys.argv[1:])
  File "/home/dev/.virtualenvs/pluto-chat/lib/python3.8/site-packages/pylint/lint/run.py", line 207, in __init__
    linter.check(args)
  File "/home/dev/.virtualenvs/pluto-chat/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 646, in check
    self._check_files(
  File "/home/dev/.virtualenvs/pluto-chat/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 681, in _check_files
    with self._astroid_module_checker() as check_astroid_module:
  File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/home/dev/.virtualenvs/pluto-chat/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 859, in _astroid_module_checker
    checker.open()
  File "/home/dev/.virtualenvs/pluto-chat/lib/python3.8/site-packages/pylint_django/checkers/foreign_key_strings.py", line 120, in open
    settings.configure(Settings(self.config.django_settings_module))
  File "/home/dev/.virtualenvs/pluto-chat/lib/python3.8/site-packages/django/conf/__init__.py", line 118, in configure
    raise RuntimeError('Settings already configured.')
RuntimeError: Settings already configured.

Pylint version:

$ pylint --version
pylint 2.14.5
astroid 2.11.7
Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.0]

Relevant pip freeze:

Django==3.2.16

slorg1 avatar Dec 05 '22 20:12 slorg1