Opened 5 years ago

Closed 5 years ago

Last modified 5 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, 5 years ago

Easy pickings: set
Summary: Specify what happens during model validation with Meta.constraintsDocument what happens during model validation with Meta.constraints.
Triage Stage: UnreviewedAccepted

comment:2 by Swatantra, 5 years ago

Owner: changed from nobody to Swatantra
Status: newassigned

comment:3 by Mariusz Felisiak, 5 years ago

Has patch: set

comment:4 by Carlton Gibson, 5 years ago

Patch needs improvement: set

comment:5 by Mariusz Felisiak, 5 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

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

Resolution: fixed
Status: assignedclosed

In 00169bc3:

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

comment:7 by Carlton Gibson <carlton.gibson@…>, 5 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, 5 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, 5 years ago

Good catch! I added clarification in PR.

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

In 230d75f5:

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

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 5 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