[Dev] Recursion problem with stale attributes and __str__

Donn Denman donn at osafoundation.org
Sat Sep 11 12:02:59 PDT 2004


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