-
Notifications
You must be signed in to change notification settings - Fork 56
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
Do not suppress sqlmigrate errors #209
Comments
Thanks for opening the issue 👍 I think that we catch these exceptions because in some cases, Django is executing a query against the DB in order to generate the SQL statement. However, I understand the point that it could fail in these cases. |
@David-Wobrock I just ran across this problem and exactly this issue happened to me. In our case this let a This was the problematic migration file contents: from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("someapp", "0306_auto_20220531_1429"),
]
operations = [
migrations.RenameField(
model_name="amodel",
old_name="old_column_name",
new_name="new_column_name",
),
] The problem for us was a kind of wonky migration chain that caused a missing state but perfectly fine SQL execution which is why we didn't catch it. This is the output from
The output from the linter indicated there was an error but:
The fix for us was to change one of other problematic migrations (the one that had the Once I fixed the state issue, I got the error on the migration file that I expected:
This definitely clears up why the suppression was added in the first place, thanks for this context! Perhaps it would be beneficial to try to whitelist these specific cases and have everything else bubble up the exception and error the linter? |
That's a very interesting use case! Thanks for sharing that :) After a bit of reflection, this is definitely a case we want to avoid. |
The next question would be, what should happen when the linter cannot analyse a migration?
Any opinion would be welcome :) |
@David-Wobrock my preference would be (1). (3) would probably be the closest to existing behavior. You mentioned above about a false-negative case the could occur:
How common is this exactly? And what would it look like to reproduce it? That could help inform the solution to not give false negatives. Or maybe the resolution to that edge case (like ignoring the migration) could simply be included in the error message. |
First, just for the record (and so that I don't forget it :P) it's a known bug in Django: https://code.djangoproject.com/ticket/26624. But in short, I have a model like:
and create a migration.
The
So the issue is that, on a project where all migrations are linted but not applied (maybe on a CI build), there is a high change that at least one migration will fail like this I think. I would actually also lean towards option (1), as it is the option where the linter is doing the least "magic". |
Now, if an error occurs while executing the
sqlmigrate
command, then as a result, the analyzer will be given an empty string instead of migrations SQL. This can cause a backwards incompatible migration to get into production and break it.django-migration-linter/django_migration_linter/migration_linter.py
Lines 295 to 318 in 76a55db
The suggestion is to add a strict check option to require the
sqlmigrate
command to be run for migration.The text was updated successfully, but these errors were encountered: