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

Squash core migrations #528

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Squash core migrations #528

wants to merge 1 commit into from

Conversation

brianhelba
Copy link
Member

No description provided.

model_name='image',
name='isic',
field=models.OneToOneField(
default=isic.core.models.isic_id.IsicId.safe_create,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is actually a bug. When this AddField is executed by the migration engine, the default is evaluated, which has the side effect of inserting rows into the IsicId table.

This didn't manifest before because (apparently), an AlterField operation to add a default doesn't trigger the evaluation. 🤷

This made me realize that it's probably a bad idea to use IsicId.safe_create as the default. Any time an instance of Image is created locally, even if it's never saved, a new IsicId row is inserted. Instead, I think ideally we should explicitly create both the IsicId and the Image in the same transaction, so that if Image creation fails, the IsicId is removed. However, I'm not sure if its possible (or even makes logical sense) to do this in a way that is robust against race conditions in IsicId duplicates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant