[Zope-Coders] SimpleItem.getId busted

Stuart Bishop stuart at stuartbishop.net
Thu Nov 20 10:50:05 EST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On 21/11/2003, at 1:40 AM, Casey Duncan wrote:

> Your version changes the semantics if id happens to be false. I think 
> getId should return the value of id if it is not None, regardless of 
> what it is.

Unfortunatly, SimpleItem.Item sets id='', so getId() will remain broken
for any class that wants to use __name__ instead of id, and has
Item as a base class. Which is one of PageTemplateFile's base classes if
you trace it through. Now I think of it, the SimpleItem.Item.id class 
attribute
makes the use of aq_base() when searching for id irrelevant.

Oh dear - my proposed change will blow the stack if getId() is called
on an object with a false id attribute and hasn't overridden __name__
from SimpleItem.Item (which is defined as __name__ == 
ComputedAttribute(getId).
I'll need to change that to reference a new function that won't 
infinitely
recurse.

>> This makes the getId() method actually work for PageTemplateFile's,
>> and all the methods that rely on it like absolute_url().
>> It is sort-of backward compatible, as people doing
>> string:${template/absolute_url}/myid to work around this bug will
>> still get valid links thanks to aquisition, but it aint pretty.
>
> Can you explain why this works for PTFs because they define __name__ 
> and not id? Also, why are you using PTFs and not skins? ;^)

See above. PageTemplateFile inherits Script inherits SimpleItem
inherits Item, and Item's class definition has id=''. The current code
thus never gets around to looking for __name__ at all (I think
PageTemplateFile should be mixing in Item_w__name__ too, but that would 
be
a seperate bug :-) )

ZopePageTemplate works as it uses self.id instead of self.__name__, 
giving
the PageTemplates product a split personality.


- --  
Stuart Bishop <stuart at stuartbishop.net>
http://www.stuartbishop.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)

iD8DBQE/vOKxAfqZj7rGN0oRAu+hAJ45d3a9GB0jRfr8pqakvjL8YV/OyACeOK/d
thEwxwVgkBGAAIZzYtjD9UM=
=QlWQ
-----END PGP SIGNATURE-----




More information about the Zope-Coders mailing list