[Django] #32703: Deferred UniqueConstraints should not be validated in validate_unique()

17 views
Skip to first unread message

Django

unread,
May 1, 2021, 2:39:34 PM5/1/21
to django-...@googlegroups.com
#32703: Deferred UniqueConstraints should not be validated in validate_unique()
-------------------------------------+-------------------------------------
Reporter: Manuel | Owner: nobody
Baclet |
Type: Bug | Status: new
Component: Database | Version: 3.1
layer (models, ORM) | Keywords: UniqueConstraint
Severity: Normal | deferrable
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
When using a deferred UniqueConstraint, we are expecting validation not to
occur before transaction commit.
Considering a model with a field `unique_valued_field` with a deferred
UniqueConstraint and two models `m1` and `m2`, we should be able to do:
{{{#!python
with transaction.atomic():
saved_value = m1.unique_valued_field
m1.unique_valued_field = m2.unique_valued_field
m2.unique_valued_field = saved_value
m1.save()
m2.save()
}}}
Currently, this raises a `ValidationError`.

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

Django

unread,
May 1, 2021, 2:44:24 PM5/1/21
to django-...@googlegroups.com
#32703: Deferred UniqueConstraints should not be validated in validate_unique()
-------------------------------------+-------------------------------------
Reporter: Manuel Baclet | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage:
deferrable | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Manuel Baclet):

* cc: Manuel Baclet (added)


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

Django

unread,
May 1, 2021, 2:49:41 PM5/1/21
to django-...@googlegroups.com
#32703: Deferred UniqueConstraints should not be validated in validate_unique()
-------------------------------------+-------------------------------------
Reporter: Manuel Baclet | Owner: nobody
Type: Bug | Status: new

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

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Manuel Baclet):

* needs_docs: 0 => 1


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

Django

unread,
May 1, 2021, 4:59:13 PM5/1/21
to django-...@googlegroups.com
#32703: Deferred UniqueConstraints should not be validated in validate_unique()
-------------------------------------+-------------------------------------
Reporter: Manuel Baclet | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage:
deferrable | Unreviewed
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Manuel Baclet:

Old description:

> When using a deferred UniqueConstraint, we are expecting validation not
> to occur before transaction commit.
> Considering a model with a field `unique_valued_field` with a deferred
> UniqueConstraint and two models `m1` and `m2`, we should be able to do:
> {{{#!python
> with transaction.atomic():
> saved_value = m1.unique_valued_field
> m1.unique_valued_field = m2.unique_valued_field
> m2.unique_valued_field = saved_value
> m1.save()
> m2.save()
> }}}
> Currently, this raises a `ValidationError`.

New description:

When using a deferred UniqueConstraint, we are expecting validation not to
occur before transaction commit.
Considering a model with a field `unique_valued_field` with a deferred

UniqueConstraint and two instances `m1` and `m2`, we should be able to do:


{{{#!python
with transaction.atomic():
saved_value = m1.unique_valued_field
m1.unique_valued_field = m2.unique_valued_field
m2.unique_valued_field = saved_value
m1.save()
m2.save()
}}}
Currently, this raises a `ValidationError`.

--

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

Django

unread,
May 2, 2021, 3:23:40 PM5/2/21
to django-...@googlegroups.com
#32703: Deferred UniqueConstraints should not be validated in validate_unique()
-------------------------------------+-------------------------------------
Reporter: Manuel Baclet | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: UniqueConstraint | Triage Stage:
deferrable | Unreviewed
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Manuel Baclet):

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


Comment:

The save method used in my test is broken. `validate_unique()` is not
called in the situation described above.

--
Ticket URL: <https://code.djangoproject.com/ticket/32703#comment:4>

Reply all
Reply to author
Forward
0 new messages