Acquisition: attribute assignment not faithful

Bug #251389 reported by Dieter Maurer
2
Affects Status Importance Assigned to Milestone
Zope 2
Invalid
Low
Unassigned

Bug Description

Usually, when you assign a value to an attribute, you would expect to retrieve the same value later from this attribute. This is not the case for "ExtensionClass" instances, as they may call the attributes "__of__" method (if any) and return its result -- a well documented feature.

The idiom "obj.__dict__[attr]" can be used to prevent "ExtensionClass" from interfering. Nevertheless, attribute assignment is not faithful for acquisition wrappers, i.e. in some cases

   >>> wrapper.attr = value
   >>> wrapper.__dict__['attr'] is value
  False

The reason for this: acquisition wrapper attribute assignment explicitely removes the acquisition context before storing the
value on the wrapped object.

Obviously, the implementer thought this a feature -- but forgot to document it.

The feature leads to highly surprising behaviour: usually acquisition wrappers mask themselves very successfully as the wrapped objects. Rarely, developers are concious whether they work with a wrapper or the base object. Now, while acquisition wrapped attributes values can faithfully be stored on the base object (e.g. in the __init__ method), they are no longer faithfully stored when the same object is wrapped. Yesterday, I spent several hours to analyse a problem caused by this behaviour.

As I expect that the feature cannot be removed (for backward compatibility reasons), I suggest to document it clearly.

Here an example for the unfaithful attribute assignment:

>>> from Acquisition import Implicit
>>> class C(Implicit):
... pass
...
>>> c0 = C()
>>> c1 = C().__of__(c0)
>>> c2 = C().__of__(c0)
>>> c1.x = c2
>>> c1.__dict__['x'] is c2
False

Revision history for this message
Hanno Schlichting (hannosch) wrote :

Patches for the documentation are welcome.

Changed in zope2:
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
Colin Watson (cjwatson) wrote :

The zope2 project on Launchpad has been archived at the request of the Zope developers (see https://answers.launchpad.net/launchpad/+question/683589 and https://answers.launchpad.net/launchpad/+question/685285). If this bug is still relevant, please refile it at https://github.com/zopefoundation/zope2.

Changed in zope2:
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.