[Django] #32370: Model._perform_unique_checks cannot properly validate simultaneous adding and changing

18 views
Skip to first unread message

Django

unread,
Jan 19, 2021, 3:35:51 PM1/19/21
to django-...@googlegroups.com
#32370: Model._perform_unique_checks cannot properly validate simultaneous adding
and changing
-------------------------------------+-------------------------------------
Reporter: Roman | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 3.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/32370>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 19, 2021, 9:24:11 PM1/19/21
to django-...@googlegroups.com
#32370: Model._perform_unique_checks cannot properly validate simultaneous adding
and changing
-------------------------------------+-------------------------------------
Reporter: Roman | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/32370#comment:1>

Django

unread,
Jan 19, 2021, 9:40:52 PM1/19/21
to django-...@googlegroups.com
#32370: Model._perform_unique_checks cannot properly validate simultaneous adding
and changing
-------------------------------------+-------------------------------------
Reporter: Roman | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

#25139 might be related or a duplicate.

--
Ticket URL: <https://code.djangoproject.com/ticket/32370#comment:2>

Django

unread,
Jan 19, 2021, 11:41:36 PM1/19/21
to django-...@googlegroups.com
#32370: Model._perform_unique_checks cannot properly validate simultaneous adding
and changing
-------------------------------------+-------------------------------------
Reporter: Roman | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* status: new => closed
* resolution: => duplicate


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/32370#comment:3>

Reply all
Reply to author
Forward
0 new messages