zope.interface.Interface.implementedBy method can corrupt

Bug #1197508 reported by Michael JasonSmith
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zope 2
Invalid
Undecided
Unassigned

Bug Description

Incorrectly using zope.interface.Interface.implementedBy on an object, rather than a class, can corrupt the object and make it unusable. Any time an attribute of the object is accessed, after using implementedBy, the following error is raised:

  File "…/zope/interface/declarations.py", line 338, in implementedByFallback
    raise TypeError("ImplementedBy called for non-factory", cls)

  TypeError: (TypeError('ImplementedBy called for non-factory', <Folder at >),
              <built-in function implementedBy>, (<Folder at >,))

It does not seem to matter which attribute is accessed, or how (getattr causes the same error as o.attr).

It appears that the root cause of the problem is a side-effect of zope.interface.declarations.implementedByFallback, which is called by implementedBy:

         cls.__implemented__ = spec

         https://github.com/zopefoundation/zope.interface/blob/master/src/zope/interface/declarations.py#L199

At the very least, implementedBy should not have a side-effect. Ever.

This side-effect turns a simple mistake into a major problem:
  http://groupserver.org/r/post/5zxOdqzn3dUyweYCAzfahP

I note that others have had similar issues:
  http://blog.fourdigits.nl/how-to-break-your-plone-site-with-implementedby

Revision history for this message
Colin Watson (cjwatson) wrote :

The zope2 project on Launchpad has been archived at the request of the Zope developers (see https://answers.launchpad.net/launchpad/+question/683589 and https://answers.launchpad.net/launchpad/+question/685285). If this bug is still relevant, please refile it at https://github.com/zopefoundation/zope2.

Changed in zope2:
status: New → 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.