zope.formlib does not correctly validate invariants with fields from a base interface.

Bug #382717 reported by Sebastian Wehrmann
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zope 2
Fix Released
Undecided
Unassigned
Zope 3
Won't Fix
Undecided
Unassigned
zope.formlib
Fix Released
Undecided
Unassigned

Bug Description

Example:

>>> import zope.interface
>>> import zope.schema

>>> class IBase(zope.interface.Interface):
... title = zope.schema.TextLine(
... title=u"Title",
... required=False)

>>> class ISub(IBase):
... sub_title = zope.schema.TextLine(
... title=u"Subtitle",
... required=False)
...
... @zope.interface.invariant
... def title_or_subtitle(obj):
... if not (obj.title or obj.sub_title):
... raise zope.interface.Invalid(
... u"Set either title or subtitle.")

When validating an object (using zope.formlib.form.checkInvariants), which implements ISub, it's not possible to access the title attribute inside the "title_or_subtitle" invariant checker method. It's explicitly filtered out, which means, that only those schema attributes, defined on the ISub interface, are available.

Is there any reason for this behavior? There is no test for this behavior.

Suggestion:

If there is no specific reason for this behavior, the invariant should get all the form field data from the request.

Revision history for this message
Sebastian Wehrmann (sw-gocept) wrote :

This bug was already fixed in zope.formlib 3.4.0 r69738 by srichter. Unfortunately, Zope 2.10 uses an older version. In Zope 2.11, the bug is fixed.

Changed in zope2:
status: New → Fix Released
Tres Seaver (tseaver)
Changed in zope3:
status: New → Won't Fix
Changed in zope.formlib:
status: New → Fix Released
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.