Validators not called on MultiValueField
|Reported by:||anonymous||Owned by:||paulcollins|
|Cc:||paulcollins||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Validators are not called for the compressed value of a MultiValueField.
If, say, I have a MultiValueField subclass which takes a first name and a last name and compresses the two into a "Lastname, Firstname" and this MultiValueField subclass was instantiated using validators = [disallow_john_doe] , one would expect that disallow_john_doe(compressed value) would be executed. However, this is not the case.
Looking at the source, it appears that while the clean() method of django.forms.fields.Field calls run_validators() , the clean() method of django.forms.fields.MultiValueField does not. This is different from expected behaviour and is not documented to my knowledge.
The workaround is to implement validate() in the subclass.
Change History (8)
comment:1 Changed 3 years ago by dmoisset
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
Changed 3 years ago by paulcollins
comment:3 follow-up: ↓ 4 Changed 3 years ago by paulcollins
- Cc paulcollins added
- Easy pickings unset
- Has patch set
- Owner changed from nobody to paulcollins
- UI/UX unset