Commit f16959ff authored by Jason Madden's avatar Jason Madden

Match the C implementation for the way in which _p_jar and _p_oid can be...

Match the C implementation for the way in which _p_jar and _p_oid can be changed. ZODB depends on this.
parent 43a64ad4
...@@ -70,9 +70,12 @@ class Persistent(object): ...@@ -70,9 +70,12 @@ class Persistent(object):
return self.__jar return self.__jar
def _set_jar(self, value): def _set_jar(self, value):
if self.__jar is not None: if self._p_is_in_cache() and value is not None and self.__jar != value:
if self.__jar != value: # The C implementation only forbids changing the jar
raise ValueError('Already assigned a data manager') # if we're already in a cache. Match its error message
raise ValueError('can not change _p_jar of cached object')
if self.__jar == value:
return
else: else:
_OSA(self, '_Persistent__jar', value) _OSA(self, '_Persistent__jar', value)
_OSA(self, '_Persistent__flags', 0) _OSA(self, '_Persistent__flags', 0)
...@@ -100,8 +103,12 @@ class Persistent(object): ...@@ -100,8 +103,12 @@ class Persistent(object):
#if value is not None: #if value is not None:
# if not isinstance(value, OID_TYPE): # if not isinstance(value, OID_TYPE):
# raise ValueError('Invalid OID type: %s' % value) # raise ValueError('Invalid OID type: %s' % value)
if self.__jar is not None and self.__oid is not None: # The C implementation only forbids changing the OID
raise ValueError('Already assigned an OID by our jar') # if we're in a cache, regardless of what the current
# value or jar is
if self._p_is_in_cache():
# match the C error message
raise ValueError('can not change _p_oid of cached object')
_OSA(self, '_Persistent__oid', value) _OSA(self, '_Persistent__oid', value)
def _del_oid(self): def _del_oid(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment