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

[fix] deviceconnection_unique_together fails due to duplicate objects #861

Merged

Conversation

Dhanus3133
Copy link
Member

Fixes #846

@coveralls
Copy link

coveralls commented May 14, 2024

Coverage Status

coverage: 98.75%. remained the same
when pulling ad99f7b on Dhanus3133:bug/deviceconnection_unique_together
into f0bdf03 on openwisp:master.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works on sqlite but as I feared, on PostgreSQL it throws this error:

django.db.utils.OperationalError: cannot ALTER TABLE "connection_deviceconnection" because it has pending trigger events

We have found out in prod that performing data migrations and schema migrations in the same migration class doesn't work well on Postgres.

Setting the atomic attribute to False has worked in my tests but it's, if anything goes wrong we will run into serious database consistency issues, it's not worth the risk.

The only reliable solution is to split the migration files:

  • the first migration file should do the data migration
  • the second data migration will perform the schema change

It will cause a bit of pain to whoever is using the dev version, because they will likely have already executed the existing migration, and running these new migrations will result into an error, but fixing that is as easy as running ./manage.py migrate connections --fake and I don't see any safer solution.

@Dhanus3133
Copy link
Member Author

@nemesifier can you review it again

@nemesifier nemesifier merged commit ab64aab into openwisp:master May 20, 2024
12 checks passed
@Dhanus3133 Dhanus3133 deleted the bug/deviceconnection_unique_together branch May 21, 2024 05:21
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

Successfully merging this pull request may close these issues.

[bug] Applying 0008_alter_deviceconnection_unique_together fails if database has duplicate objects
3 participants