3YOURMIND / django-migration-linter

:rocket: Detect backward incompatible migrations for your django project
https://pypi.python.org/pypi/django-migration-linter/
Apache License 2.0
523 stars 57 forks source link

django-lint-migrations@2.5.0 fails after update #139

Closed sobolevn closed 3 years ago

sobolevn commented 3 years ago

Traceback:

+ python manage.py lintmigrations --exclude-apps=axes --warnings-as-errors
Traceback (most recent call last):
  File "manage.py", line 31, in <module>
    main()
  File "manage.py", line 27, in main
    management.execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.8/site-packages/django_migration_linter/management/commands/lintmigrations.py", line 133, in handle
    config_parser.read(DEFAULT_CONFIG_FILES)
  File "/usr/local/lib/python3.8/configparser.py", line 697, in read
    self._read(fp, filename)
  File "/usr/local/lib/python3.8/configparser.py", line 1082, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
configparser.MissingSectionHeaderError: File contains no section headers.
file: '.editorconfig', line: 3
'root = true\n'

CI link: https://github.com/wemake-services/wemake-django-template/pull/1455/checks?check_run_id=1803497890 Reproduction: https://github.com/wemake-services/wemake-django-template/pull/1455

David-Wobrock commented 3 years ago

Thanks for all the information! I'll try to suggest a fix in the next few days (hopefully today) :)

skarzi commented 3 years ago

That's because of the following line:

root = true

It will be nice to log some message on WARNING or ERROR level instead of raising an exception, but imho the best solution is to load config only from 1 file (e.g. first matched file from DEFAULT_CONFIG_FILES). It will be also great to have some CLI flag --config to set path to the config file - custom one (not included in DEFAULT_CONFIG_FILES) or just to avoid loading all files defined in the before-mentioned constant.

sobolevn commented 3 years ago

@skarzi just to be clear: this is a valid .editorconfig format. https://editorconfig.org/

skarzi commented 3 years ago

.editorconfig also doesn't seem to be a good place to store the configuration of Django's migration linter, what do you think about removing it from the defaults tuple?

David-Wobrock commented 3 years ago

Good point, it doesn't make that much sense to put the config in the editorconfig file :+1:

skarzi commented 3 years ago

@David-Wobrock and what do you think about adding an option like --config config-path to CLI?

David-Wobrock commented 3 years ago

For now, let's remove the .editorconfig from the file list. Adding this option is definitely an option for the next version :)

The Python configparser always expects section headers in the config files, which is not appropriate for editorconfig

David-Wobrock commented 3 years ago

@David-Wobrock and what do you think about adding an option like --config config-path to CLI?

I'll let you open an issue for this :)

David-Wobrock commented 3 years ago

2.5.1 released, hope everything works as expected now :)

Thanks for the help!

sobolevn commented 3 years ago

Yes, it works now! Thanks @David-Wobrock https://github.com/wemake-services/wemake-django-template/pull/1462