Opened 88 minutes ago
Last modified 82 minutes ago
#37502 assigned Cleanup/optimization
Document which constraints model formsets validate across forms — at Version 1
| Reported by: | Clifford Gama | Owned by: | Clifford Gama |
|---|---|---|---|
| Component: | Documentation | Version: | dev |
| Severity: | Normal | Keywords: | ModelFormSet, formset |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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_messageisn'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 raiseIntegrityError.
Thanks Tim Schilling for the nudge to revive this work.