Opened 4 years ago

Closed 4 years ago

#32370 closed Bug (duplicate)

Model._perform_unique_checks cannot properly validate simultaneous adding and changing

Reported by: Roman Owned by: nobody
Component: Database layer (models, ORM) Version: 3.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Imagine there is a model with a unique field.

class Test(models.Model):
    index = models.PositiveIntegerField()
    name = models.CharField(max_length=256)

    class Meta:
        constraints = (
            models.UniqueConstraint(
                fields=('index'),
                name='%(app_label)s_%(class)s_U1'),
        )

If I have one model with values (0, "old") and then try to update existing model to (1, "old") and simultaneously add (0, "new"), checks in Model._perform_unique_checks fail, despite there will be no constraint violation at the end of transaction.

Change History (3)

comment:1 by Simon Charette, 4 years ago

Does the problem manifests itself if you use define your unique constraint using index = models.PositiveIntegerField(unique=True) instead of relying on Meta.constraints?

comment:2 by Tim Graham, 4 years ago

#25139 might be related or a duplicate.

comment:3 by Simon Charette, 4 years ago

Resolution: duplicate
Status: newclosed

yeah that was my thought as well, I'll close for now as it seems like just another flavor of #25139 using a new API.

Note: See TracTickets for help on using tickets.
Back to Top