OFS.SimpleItem initialization problem: infinite loop

Bug #142910 reported by Jean-François Doyon
2
Affects Status Importance Assigned to Milestone
Zope 2
Invalid
Low
Unassigned

Bug Description

This is a Zope core bug discovered while doing a custom CMF content type.

I have a class that subclasses Product.CMFDefault.File (which eventually leads to OFS.SimpleItem).
This class overloads __init__ with a dumb 2 line one.

When migrating from 2.6.3 to 2.7, the said CMF content type can't be viewed, showing the error:

>Zope Error
>Zope has encountered an error while publishing this resource.
>
>Error Type: RuntimeError
>Error Value: maximum recursion depth exceeded
> ...
>Module ZPublisher.Publish, line 94, in publish
>Module Zope.App.startup, line 257, in recordMetaData
>Module OFS.SimpleItem, line 333, in getPhysicalPath
>Module OFS.SimpleItem, line 76, in
>Module OFS.SimpleItem, line 310, in getId
>Module OFS.SimpleItem, line 76, in
>Module OFS.SimpleItem, line 310, in getId
>Module OFS.SimpleItem, line 76, in
>Module OFS.SimpleItem, line 310, in getId
> ...

An infinite loop !!

From Dieter:

>This is a bug in "OFS.SimpleItem.Item_w__name__".
>
> In its base class, "__name__" is defined as
> "ComputedAttribute(lambda self: self.getId())"
> and it defines "getId()" to return "self.__name__".
> Apparently, this is an infinite recursion.
>
>Please file a bug report to "http://www.zope.org/Collectors/Zope".
>
>You can fix this problem by giving "Item_w__name__" a default
>class level attribute or "__name__ = ''".
>
>You can work around the bug by assigning an "id" for your
>object with its "_setId" method (this overrides "__name__").

In my case, after tracking this down, I decided that I really shouldn't have overloaded the __init__ since I didn't need to (I tend to do it out of habbit), so I removed it from my class, and re-created the instances (I only had a few).

Thanks,
J.F.

Tags: bugday
Revision history for this message
João Marcus Christ (joaoma) wrote :

This breaks FileSystemStorage, so a fix for this seems to be important

Replacing:
self.__name__
with:
self.id

seems to fix it

Revision history for this message
João Marcus Christ (joaoma) wrote :

Sorry, that doesn't fix it! Breaks ZMI

Revision history for this message
Tres Seaver (tseaver) wrote :

Using '_setId' is the standard protocol for assigning a SimpleItem's __name__ / ID.

I'm fine with seeing a class default for '__name__', but only if the patch adds a test
which demonstrates the problem, i.e. fails without the default.

Changed in zope2:
importance: Medium → Low
status: New → Triaged
tags: added: bugday
removed: bug zope
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: Triaged → 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.