Opened 3 years ago

Closed 3 years ago

#32703 closed Bug (invalid)

Deferred UniqueConstraints should not be validated in validate_unique()

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

Description (last modified by Manuel Baclet)

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:

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.

Change History (4)

comment:1 by Manuel Baclet, 3 years ago

Cc: Manuel Baclet added

comment:2 by Manuel Baclet, 3 years ago

Needs documentation: set

comment:3 by Manuel Baclet, 3 years ago

Description: modified (diff)

comment:4 by Manuel Baclet, 3 years ago

Resolution: invalid
Status: newclosed

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

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