Opened 3 weeks ago

Last modified 6 days ago

#37502 assigned Cleanup/optimization

Document which constraints model formsets validate across forms

Reported by: Clifford Gama Owned by: Clifford Gama
Component: Documentation Version: dev
Severity: Normal Keywords: ModelFormSet, formset
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Clifford Gama)

Model formsets validate unique, unique_together, unique_for_date|month|year, and UniqueConstraints with fields and no condition across forms in the formset (#9493, #30581). This is only mentioned in passing, in ​Overriding clean() on a ModelFormSet, as the reason to call super().clean(). That passage lists only the first three. The UniqueConstraint support added in #30581 was never documented for formsets.

The docs also don't say:

  • that violation_error_message isn't used for cross-form errors; a generic "Please correct the duplicate data for …" message is shown instead;
  • that other constraints (conditional or expression-based UniqueConstraints, ExclusionConstraint) are checked only against existing rows, not across forms, so saving can raise IntegrityError.

​PR

Thanks Tim Schilling for the nudge to revive this work.

Change History (5)

comment:1 by Clifford Gama, 3 weeks ago

Description: modified (diff)

comment:2 by Jacob Walls, 3 weeks ago

Triage Stage: Unreviewed → Accepted

The violation_error_message problem seems like something we could easily fix. If you reckon so, do you want to split that into a separate ticket?

comment:3 by Clifford Gama, 3 weeks ago

Patch needs improvement: set

Marking as PNI while I investigate about the violation_error_message.

comment:4 by Clifford Gama, 6 days ago

Opened ticket #37550 for the violation_error_message issue.

comment:5 by Clifford Gama, 6 days ago

Patch needs improvement: unset
Note: See TracTickets for help on using tickets.
Back to Top