two object is the same
In my unittest, I have to check that a specified zodb object is the same (e.g. not deleted and recreated) after an operation as it was before. I thought I could do this: ob = df._getOb(drid) [...] # do something if ob is not df._getOb(drid): # object changed ('df' is inherited from Folder, 'ob' is from SimpleItem) However this doesn't work because the 'is' operator uses the memory address of the objects and these are not the same in subsequent calls: (Pdb) id(df._getOb(drid)) 177727520 (Pdb) id(df._getOb(drid)) 177727424 (Pdb) id(df._getOb(drid)) 177727520 (Pdb) id(df._getOb(drid)) 177727424 (Pdb) id(df._getOb(drid)) 177727520 (Pdb) id(df._getOb(drid)) 177727424 Is there any deterministic way for performing the check above? Regards, Sandor
zope@netchan.cotse.net wrote at 2004-3-30 13:15 -0600:
In my unittest, I have to check that a specified zodb object is the same (e.g. not deleted and recreated) after an operation as it was before. I thought I could do this:
ob = df._getOb(drid) [...] # do something if ob is not df._getOb(drid): # object changed
('df' is inherited from Folder, 'ob' is from SimpleItem)
However this doesn't work because the 'is' operator uses the memory address of the objects and these are not the same in subsequent calls:
Use "==" instead of "is". Alternatives: * use the "aq_base" attribute (it returns the non acquisition wrapped base object) with "is" * compare the "_p_oid" attribute or "absolute_url()" values. -- Dieter
participants (2)
-
Dieter Maurer -
zope@netchan.cotse.net