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
524 stars 57 forks source link

Ignored/excluded warnings/errors should be re-evaluated to the current options when reusing cache #277

Open lieryan opened 8 months ago

lieryan commented 8 months ago

Suppose that I have an app with one erroneous file:

$ ./manage.py lintmigrations --git-commit-id mycommit --no-cache --include-apps myapp  ; echo $?
*** Summary ***
Valid migrations: 0/15
Erroneous migrations: 1/15
Migrations with warnings: 0/15
Ignored migrations: 14/15
1

I can disable that warning with --exclude-migration-test:

$ ./manage.py lintmigrations --git-commit-id mycommit --no-cache --include-apps myapp --exclude-migration-test DROP_COLUMN DROP_TABLE  ; echo $?
*** Summary ***
Valid migrations: 1/15
Erroneous migrations: 0/15
Migrations with warnings: 0/15
Ignored migrations: 14/15
0

This is working well when passing --no-cache.

However, when caching is enabled:

$ ./manage.py lintmigrations --git-commit-id mycommit --cache-path dml-cache --include-apps myapp  ; echo $?
*** Summary ***
Valid migrations: 0/15
Erroneous migrations: 1/15
Migrations with warnings: 0/15
Ignored migrations: 14/15
1

When I re-run the command again with --exclude-migration-test, the result seems to have become fixated to the previous option due to the cache:

$ ./manage.py lintmigrations --git-commit-id mycommit --cache-path dml-cache --include-apps myapp --exclude-migration-test DROP_COLUMN DROP_TABLE  ; echo $?
*** Summary ***
Valid migrations: 0/15
Erroneous migrations: 1/15
Migrations with warnings: 0/15
Ignored migrations: 14/15
1

Same issue with --warnings-as-errors as well.

What I expect is that I should be able to re-run lintmigrations with different options and get the latest result based on the current set of options. django-migration-linter should either not cache anything that is based on the current options or it should bust the cache whenever the options changed.

This is particularly problematic because caching is always enabled by default when you don't pass in --cache-path or --no-cache. It leads to extremely confusing behavior that the options from previous runs affects the result of current run.