ContainedProxy not working for mutable non-persistent objects
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zope 3 |
Won't Fix
|
Undecided
|
Unassigned | ||
zope.container |
Invalid
|
Medium
|
Unassigned |
Bug Description
I'll upload a patch to test_contained.py that demonstrates the problem.
Basically, the issue is that ContainedProxy uses the argument to __new__ as the only way to set the state of the proxied object. However, __new__ is only called for objects that are not in the cache. If the ContainedProxy object is a ghost, the proxied object will not be updated.
I think a fix needs to handle non-persistent objects differently by adding a setProxiedObject function and changing __getnewargs__, __getstate__, and __setstate__ to use a different format for non-persistent objects. Here is what I propose:
__getnewargs__ is changed to return None if proxy_object is not an instance of Persistent.
__getstate__ is extended to (__name__, __parent__, proxy_object) if proxy_object is not an instance of Persistent.
__setstate__ checks length of the "state" tuple and calls setProxiedObject if there is a 3rd arg.
__reduce__ and __reduce_ex__ are changed to match the change in __getstate__ .
In addition, we might want to change the __setattr__ implementation to check if we are wrapping a non-persistent object and automatically set the _p_changed attribute if we are.
Changed in zope3: | |
status: | New → Won't Fix |
tags: | added: bugday20100424 |
This patch extends the test_basic_ persistent_ w_non_persisten t_proxied test by mutating the proxied object and verifying the change. It fails with the current implementation.