Skip to content
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

False Positive When Using SeparateDatabaseAndState #294

Open
johnnymetz opened this issue Jan 7, 2025 · 0 comments
Open

False Positive When Using SeparateDatabaseAndState #294

johnnymetz opened this issue Jan 7, 2025 · 0 comments

Comments

@johnnymetz
Copy link

johnnymetz commented Jan 7, 2025

Steps to Reproduce

Let's say I have the following Django model:

class Product(models.Model):
    name = models.CharField(max_length=255)
    rating = models.IntegerField(null=True, blank=True)

I want to remove the rating field in a backwards-compatible way, so I create the following two migrations:

Migration 1: Remove rating field from the state

# 0002_remove_product_rating_from_state.py
class Migration(migrations.Migration):
    dependencies = [
        ("appname", "0001_initial"),
    ]

    operations = [
        migrations.SeparateDatabaseAndState(
            state_operations=[
                migrations.RemoveField(
                    model_name="product",
                    name="rating",
                ),
            ],
            database_operations=[],
        ),
    ]

Migration 2: Remove rating field from the database

# 0003_remove_product_rating_from_db.py
class Migration(migrations.Migration):
    dependencies = [
        ("appname", "0002_remove_product_rating_from_state"),
    ]

    operations = [
        migrations.SeparateDatabaseAndState(
            state_operations=[],
            database_operations=[
                migrations.RunSQL(
                    "ALTER TABLE product DROP COLUMN rating;"
                ),
            ],
        ),
    ]

The lintmigrations command reports that 0003_remove_product_rating_from_db is backwards incompatible:

$ python manage.py lintmigrations -q ok
(api, 0004_remove_metabase_field_from_db)... ERR
	DROPPING columns

Expected Result

The lintmigrations should show no errors. The rating field was removed from the state in 0002_remove_product_rating_from_state which makes 0003_remove_product_rating_from_db backwards compatible.

Questions / Comments

Does this seem like the correct solution? One issue is that these two migrations are ONLY backwards compatible if they're deployed separately. Deploying them both at once is obviously backwards incompatible.

If we can't track / enforce when these migrations are deployed, is the recommended solution to continue to report as backwards incompatible and require the user to ignore the false positive?

$ python manage.py lintmigrations -q ok -- ignore_name 0004_remove_metabase_field_from_db
# No errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant