Object field validation in _field.py fails

Bug #301226 reported by Tim Cook
4
Affects Status Importance Assigned to Milestone
Zope 3
Invalid
Undecided
Unassigned
grok
Invalid
Undecided
Unassigned

Bug Description

When a schema contains a reference via the Object field type to another schema that contains another reference to a schema via the Object field type the _validate_fields function incorrectly causes and exception at line 467 in _field.py

As discussed in this thread on the mailing list.
http://mail.zope.org/pipermail/zope3-users/2008-October/008215.html

This seems to be because if errors is None it is assigned as an empty list. When the second call is made it appears to append another empty list to the outer one. Therefore the outer list is no longer empty and raises the exception.

This is a show stopper for my project where we have dozens of these chains.

My solution that seems to still catch a valid exception and not fail incorrectly is to change the _validate_fields function to the code below. However, I do not know if there are other ramifications with the ZCA.

def _validate_fields(schema, value, errors=None):
    if errors is not None:
        #errors = []
        for name in schema.names(all=True):
            if not IMethod.providedBy(schema[name]):
                try:
                    attribute = schema[name]
                    if IField.providedBy(attribute):
                        # validate attributes that are fields
                        attribute.validate(getattr(value, name))
                except ValidationError, error:
                    errors.append(error)
                except AttributeError, error:
                    # property for the given name is not implemented
                    errors.append(SchemaNotFullyImplemented(error))
    return errors

Changed in grok:
status: New → Incomplete
Changed in zope3:
status: New → Invalid
Changed in grok:
status: Incomplete → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.