[ZODB-Dev] Re: getting the object ID (_p_oid attribute)

Florent Guillaume fg at nuxeo.com
Mon Jun 26 15:32:03 EDT 2006


On 26 Jun 2006, at 21:28, Robert Gravina wrote:
>>>>     def __eq__(self, other):
>>>>         if isinstance(other, <name of my class>):
>>>>             if hasattr(other,"_p_oid") and other._p_oid != None  
>>>> and (other._p_oid == self._p_oid):
>>>>                 return True
>>>>             else:
>>>>                 return False
>>>>
>>>> and now can compare objects for equality after the (Twisted)  
>>>> client edits them and sends them back.
>>>
>>> You can shorten that to
>>> def __eq__(self, other):
>>>     return aq_base(self) is aq_base(other)
>>
>> Heh, good point.
>>
>
> I assume you're referring to repacing just "isinstance(other, <name  
> of my class>)"? Actually, to be honest I don't even know what  
> Acquisition based classes are, so I'm probably not using them. I'm  
> just subclassing Persistent

No, replacing the whole function. The ZODB ensures that, in a given  
connection (ie thead usually) peristent objects with the same oid  
have the same identity (that's the purpose of the "pickle cache" and  
"_added" cache if you're interested in internals).

Florent

-- 
Florent Guillaume, Nuxeo (Paris, France)   Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   fg at nuxeo.com





More information about the ZODB-Dev mailing list