[Dev] Re: Recursion problem with stale attributes and __str__

Andi Vajda vajda at osafoundation.org
Tue Sep 14 11:13:44 PDT 2004


When a python item object goes stale, its Chandler attribute values and 
references are unloaded from memory, the item is hollowed out. Accessing that 
item instance is not going to yield much but grief.
I changed the 'item is stale' error into a proper StaleItemError which makes 
sure to call the item's intrinsic __repr__() method instead of potential 
overrides.

Andi..

On Sat, 11 Sep 2004, Donn Denman wrote:

> Andi,
>
> Item.getAttributeValue converts an item into a string when the item is stale 
> and an exception is being raised.  (See Item.py, line 541)  Unfortunately 
> this can lead to infinite recursion for any item that implements a string 
> conversion method which accesses one if its attributes.    I ran in to this 
> with my EmailAddress item, which implements __str__().   The trace goes like 
> this: the raise converts to string, which calls my __str__, which calls 
> __getattr__, which calls getAttributeValue(), which again raises the 
> exception.
>
> I'm not sure how big of a problem it is, because I'd guess that the stale 
> item exception isn't often handled with an exception handler, rather it 
> reflects a design problem with the overall software.  But the recursion 
> causes trouble for debugging too, so it probably deserves more thought and 
> discussion.  I'm also wondering how widespread and how deep the problem is. 
> There appear to be several places in the code where you are giving nice 
> diagnostic information which can trigger this recursion when converting to 
> string.  But there may be other special methods that get implicitly accessed 
> by Item that could trigger this recursion too.  It's easy enough to fix the 
> specific case: you just change the message in the raise to use a "safe" way 
> to identify the item.  E.g. avoid converting the item into a string, but list 
> its kind and displayName instead.   It's the more general problem that really 
> worries me.  Almost anything that manipulates an item in getAttributeValue() 
> could recurse if the item has overloaded a special method.   For the general 
> problem, we might want to disable the recursion.  Maybe there's some guidance 
> handling this issue in the python community, so I'll post to Dev for 
> comments.
>
> - Donn Denman
>
>


More information about the Dev mailing list