Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#30547 closed Cleanup/optimization (fixed)

Document what happens during model validation with Meta.constraints.

Reported by: Dirk Groten Owned by: Swatantra
Component: Documentation Version: 2.2
Severity: Normal Keywords: constraints, UniqueConstraint
Cc: Kevin Christopher Henry Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The current ​constraints reference does not mention whether or not a ValidationError is raised during model validation if a constraint fails. The documentation only mentions that a database constraint is created.

However, for the soon to be deprecated unique_together, there is a reference to model validation.

As far as I can see, a UniqueConstraint causes validate_unique() to check for uniqueness and raises a ValidationError. But a CheckConstraint does not cause a ValidationError when the model is validated. I believe it's important to mention this in the documentation.

Change History (11)

comment:1 by Mariusz Felisiak, 7 years ago

Easy pickings: set
Summary: Specify what happens during model validation with Meta.constraints → Document what happens during model validation with Meta.constraints.
Triage Stage: Unreviewed → Accepted

comment:2 by Swatantra, 7 years ago

Owner: changed from nobody to Swatantra
Status: new → assigned

comment:3 by Mariusz Felisiak, 7 years ago

Has patch: set

comment:4 by Carlton Gibson, 7 years ago

Patch needs improvement: set

comment:5 by Mariusz Felisiak, 7 years ago

Patch needs improvement: unset
Triage Stage: Accepted → Ready for checkin

comment:6 by Carlton Gibson <carlton.gibson@…>, 7 years ago

Resolution: → fixed
Status: assigned → closed

In 00169bc3:

Fixed #30547 -- Doc'd how Meta.constraints affect model validation.

comment:7 by Carlton Gibson <carlton.gibson@…>, 7 years ago

In c3a0f76d:

[2.2.x] Fixed #30547 -- Doc'd how Meta.constraints affect model validation.

Backport of 00169bc36156d4a32546229bf39de91213709eaf from master

comment:8 by Kevin Christopher Henry, 7 years ago

Cc: Kevin Christopher Henry added

I suggest that the note be expanded to indicate that uniqueness validation does not work if the condition parameter is used (i.e. for partial unique indexes). Based on ​this comment it appears to be a hard problem, and unlikely to be implemented any time soon.

comment:9 by Mariusz Felisiak, 7 years ago

Good catch! I added clarification in ​PR.

comment:10 by GitHub <noreply@…>, 7 years ago

In 230d75f5:

Refs #30547 -- Clarified that partial UniqueConstraints don't affect model validation.

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 7 years ago

In 0088e592:

[2.2.x] Refs #30547 -- Clarified that partial UniqueConstraints don't affect model validation.

Backport of 230d75f59c43b9731465c4ec92ad714e301637b8 from master

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