The docs include an example of multi-field in-field validation. The linked example suggests using field.parent.<otherfield>.value as follows:
>>> def passwd2_validator(value, field):
... if field.parent.passwd1.value != value:
... raise validators.ValidationError('Password do not match')
This will not work as expected in cases where an empty value for <otherfield> is submitted and the previous / persisted value of model.<otherfield> is not None. In these cases <otherfield>.value will return the previous value in the model instead of the submitted value in the request.
Although this does not affect this particular example - because "password confirmation" fields are typically not persisted - the example may be misleading to users who are looking to implement multi-field validation.
One workaround is to use _deserialize() instead:
>>> def passwd2_validator(value, field):
... if field.parent.passwd1._deserialize() != value:
... raise validators.ValidationError('Password do not match')
Or better yet, users should be directed to implement multi-field validation as a global (fieldset-level) validator that is run after all independent field-level validation is complete.
The docs include an example of multi-field in-field validation. The linked example suggests using
field.parent.<otherfield>.value
as follows:This will not work as expected in cases where an empty value for
<otherfield>
is submitted and the previous / persisted value ofmodel.<otherfield>
is not None. In these cases<otherfield>.value
will return the previous value in the model instead of the submitted value in the request.Although this does not affect this particular example - because "password confirmation" fields are typically not persisted - the example may be misleading to users who are looking to implement multi-field validation.
One workaround is to use _deserialize() instead:
Or better yet, users should be directed to implement multi-field validation as a global (fieldset-level) validator that is run after all independent field-level validation is complete.