Randomness (RE: [Zope-dev] CoreSessionTracking 0.8)
Chris McDonough
chrism@digicool.com
Fri, 25 May 2001 05:38:46 -0400
Chris McDonough wrote:
> If the answer is 2, everything's not so fine. I'll likely need to
> change the CST code to unwrap acquisition-wrapped objects before storing
> them, just to head potential problems off at the pass. I just did a
> preliminary test, and it appears that it *is* storing
> acquisition-wrapped objects. This is bad if it's true. :-(
Note that I just changed CST to unwrap aq-wrapped objects just in case,
because what little testing I've been able to do says that aquisition
wrappers are being stored in ZODB. I'm sure someone's going to come
along and tell me that's the dumbest thing they've ever heard, but the
changes don't hurt anything if I'm wrong.
The requisite changes to the SessionData class (in the SessionData.py
module) are:
from:
def __setitem__(self, k, v):
# if the key or value is a persistent instance,
# set up its _p_jar immediately
if hasattr(v, '_p_jar') and v._p_jar is None:
v._p_jar = self._p_jar
v._p_changed = 1
if hasattr(k, '_p_jar') and k._p_jar is None:
k._p_jar = self._p_jar
k._p_changed = 1
self._container[k] = v
self._p_changed = 1
to:
def __setitem__(self, k, v):
# if the key or value is a persistent instance,
# set up its _p_jar immediately
if hasattr(v, '_p_jar') and v._p_jar is None:
v._p_jar = self._p_jar
v._p_changed = 1
if hasattr(k, '_p_jar') and k._p_jar is None:
k._p_jar = self._p_jar
k._p_changed = 1
# unwrap this thing if it's wrapped
from Acquisition import aq_base
k = aq_base(k)
v = aq_base(v)
self._container[k] = v
self._p_changed = 1
weeping (although grateful for the exchange),
- C