Opened 13 months ago

Closed 13 months ago

Last modified 12 months 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 Changed 13 months ago by felixxm

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 Changed 13 months ago by Swatantra

Owner: changed from nobody to Swatantra
Status: newassigned

comment:3 Changed 13 months ago by felixxm

Has patch: set

comment:4 Changed 13 months ago by Carlton Gibson

Patch needs improvement: set

comment:5 Changed 13 months ago by felixxm

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:6 Changed 13 months ago by Carlton Gibson <carlton.gibson@…>

Resolution: fixed
Status: assignedclosed

In 00169bc3:

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

comment:7 Changed 13 months ago by Carlton Gibson <carlton.gibson@…>

In c3a0f76d:

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

Backport of 00169bc36156d4a32546229bf39de91213709eaf from master

comment:8 Changed 12 months ago by Kevin Christopher Henry

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 Changed 12 months ago by felixxm

Good catch! I added clarification in PR.

comment:10 Changed 12 months ago by GitHub <noreply@…>

In 230d75f5:

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

comment:11 Changed 12 months ago by Mariusz Felisiak <felisiak.mariusz@…>

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