Re: [Zope] How to see if two objects are the same (minor fix)
Ron Bickers writes:
I want to see if an object is the one aqcuired from the root, but I'm hitting walls.
<dtml-var "PARENTS[-1].myObject"> <dtml-var "myObject"> <dtml-var "PARENTS[-1].myObject is myObject">
This returns the following when in the root folder context:
<TinyTable instance at 8684ad8> <TinyTable instance at 8684ad8> 0 What you see here, is Zope's (more precisely ExtensionClass's) acquisition magic:
when you access "object.attribute", you (usually) will not get the object corresponding to "attribute" but a new object: "attribute.__of__(object)" i.e. the attribute object in the context of "object". When you look up an attribute of this object, it will first in the object itself and when it does not success there, it will look in the context. That is what you like with acquisition. The downside: When you access the "same" object via different contexts, you will in fact get different objects (as the contexts are different). "is" will return false, as it should be. But, even, if you use "==", you will get "false". There have been some discussion in the list, whether this is the best behaviour. What can you do? You can use the "aq_base" attribute to strip away any context and get to the base object. At least in Zope 2.2.1, "aq_base" was not exposed to DTML. Thus, you would need an external method, say "getBaseObject", to get at the base: def getBaseObject(object): return getattr(object,'aq_base',object) With this function, you can compare the base objects: <dtml-var "getBaseObject(myvar) is getBaseObject(PARENT[-1].myvar)"> Be careful, however: Even, if such a test returns true for two objects, the objects may nevertheless have different behaviour (as the contexts are different). Dieter
Chris Withers writes:
Dieter Maurer wrote:
At least in Zope 2.2.1, "aq_base" was not exposed to DTML.
....and I don't think it ever would or should be sicne it strips off all security context and would probably let you do 'bad things' :-S I do not think, an object without any acquisition (and security) context is a big security risk. The lack of a security context means, that the default security setting built into the Zope security policy is used. In Zope 2.2.2., this means, only "Manager" can do anything, unless the object itself mapped some permissions itself to roles (which then remain valid even for the base object).
However, I see another danger. As old (now fixed) bugs in "ZopeFind" have demonstrated, objects stripped of their acquisition context lead to very strange errors, where suddenly even Manager cannot use the object any more. Thus, I agree that "aq_base" should not be exposed, even if for a different reason. Dieter
-----Original Message----- From: Chris Withers [mailto:chrisw@nipltd.com]
Dieter Maurer wrote:
At least in Zope 2.2.1, "aq_base" was not exposed to DTML.
...and I don't think it ever would or should be sicne it strips off all security context and would probably let you do 'bad things' :-S
Well... aq_base appears to work just fine in a Python method (not external). Is that a bad thing? I ended up creating a sameObject Python method that compares two objects' aq_base and it does what I expect. I'm using it to determine if I need to display the global menu under the local menu, or if the global menu *is* the local menu, so different context behavior isn't an issue. I suppose an upcoming Zope will take care of this problem if it gives the intuitive results with an == comparison. Thanks for all of your help!! _______________________ Ron Bickers Logic Etc, Inc. rbickers@logicetc.com
From: Chris Withers <chrisw@nipltd.com>
Ron Bickers wrote:
Well... aq_base appears to work just fine in a Python method (not external). Is that a bad thing?
Probably, although someone from DC would need to comment why...
Hmm... Evan, should that be the case?
Shh! Not so loud! ;-) Yes, sadly, this is an area where the current release of PythonMethod fails to correctly implement security. Cheers, Evan @ digicool & 4-am
participants (4)
-
Chris Withers -
Dieter Maurer -
Evan Simpson -
Ron Bickers