[zope2-tracker] [Bug 382717] [NEW] zope.formlib does not correctly validate invariants with fields from a base interface.

Sebastian Wehrmann sw at gocept.com
Tue Jun 2 07:59:30 EDT 2009


Public bug reported:

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.

** Affects: zope2
     Importance: Undecided
         Status: New

** Affects: zope3
     Importance: Undecided
         Status: New

** Also affects: zope2
   Importance: Undecided
       Status: New

-- 
zope.formlib does not correctly validate invariants with fields from a base interface.
https://bugs.launchpad.net/bugs/382717
You received this bug notification because you are a member of Zope 2
Developers, which is subscribed to Zope 2.


More information about the zope2-tracker mailing list