Opened 14 years ago
Closed 13 years ago
#14184 closed Bug (fixed)
Validators not called on MultiValueField
Reported by: | anonymous | Owned by: | Paul Collins |
---|---|---|---|
Component: | Forms | Version: | 1.2 |
Severity: | Normal | Keywords: | MultiValueField Validators |
Cc: | Paul Collins | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Attachments (2)
Change History (8)
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
by , 13 years ago
Attachment: | add_run_validators_call.patch added |
---|
follow-up: 4 comment:3 by , 13 years ago
Cc: | added |
---|---|
Easy pickings: | unset |
Has patch: | set |
Owner: | changed from | to
UI/UX: | unset |
Was a bit surprised by this one myself. I'm working on the idea that the MultiValueField is wrong rather than the docs since the validators arg is a core Field arg. Patch includes a regression test for this and a fix which appears to resolve the issue.
On a related note MultiValueField.validate is overridden to be a noop, but the parent class Field checks if the field is required. I've left it alone but, should MultiValueField.validate be removed so that the Field.validate gets called instead?
by , 13 years ago
Attachment: | add_run_validators_call.2.patch added |
---|
comment:4 by , 13 years ago
Replying to paulcollins:
On a related note MultiValueField.validate is overridden to be a noop, but the parent class Field checks if the field is required. I've left it alone but, should MultiValueField.validate be removed so that the Field.validate gets called instead?
Never mind, eventually rereading the clean function for the MultiValueField answered my question. Seems the clean method already does the work of the Field.validate method.
comment:5 by , 13 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Either the documentation or MultiValueField are wrong. (I'd say that MultiValueField is). Accepting