[Zope-dev] Object schema field validation
Markus Kemmerling
markus.kemmerling at meduniwien.ac.at
Sun Nov 29 06:02:36 EST 2009
I stumbled upon a problem with Object schema field validation. The problem occurs, e.g., if the the Object field's schema itself contains a Choice field with a dynamically computed vocabulary. For the latter to validate correctly the field must be bound to the instance. But the Object field validation code in zope.schema._fields._validate_fields validates the attributes of the Object field instance without binding them first:
def _validate_fields(schema, value, errors=None):
...
try:
attribute = schema[name]
if IField.providedBy(attribute):
# validate attributes that are fields
attribute.validate(getattr(value, name))
except ValidationError, error:
...
Replacing the line
attribute.validate(getattr(value, name))
with
field = attribute.bind(value)
field.validate(getattr(value, name))
fixes the problem.
Looks like a bug to me.
Regards,
Markus Kemmerling
More information about the Zope-Dev
mailing list