Commit b0897986 authored by Tres Seaver's avatar Tres Seaver

Make deleting '_p_oid' in Python Persistent work like C too.

parent cf576871
......@@ -4,9 +4,9 @@
4.0.8 (Unreleased)
------------------
- Make it possible to delete the ``_p_jar`` of a pure-Python
``Persistent`` object (fixes aborting a ZODB Connection that
has added objects).
- Make it possible to delete ``_p_jar`` / ``_p_oid`` of a pure-Python
``Persistent`` object which has been removed from the jar's cache
(fixes aborting a ZODB Connection that has added objects). (PR #7)
4.0.7 (2014-02-20)
------------------
......
......@@ -98,8 +98,11 @@ class Persistent(object):
self.__oid = value
def _del_oid(self):
if self.__jar is not None:
raise ValueError('Cannot delete OID once assigned to a jar')
jar = self.__jar
oid = self.__oid
if jar is not None:
if oid and jar._cache.get(oid):
raise ValueError('Cannot delete _p_oid of cached object')
self.__oid = None
_p_oid = property(_get_oid, _set_oid, _del_oid)
......
......@@ -86,23 +86,20 @@ class _Persistent_Base(object):
self.assertEqual(inst._p_sticky, False)
self.assertEqual(inst._p_status, 'unsaved')
def test_cannot_del_jar_while_in_cache(self):
def test_del_jar_while_in_cache(self):
inst, _, OID = self._makeOneWithJar()
def _test():
del inst._p_jar
self.assertRaises(ValueError, _test)
def test_del_jar_oid_like_ZODB_abort(self):
# When a ZODB connection aborts,
# it removes registered objects from the cache,
# deletes their jar, deletes their OID
# and finally sets p_changed to false
def test_del_jar_like_ZODB_abort(self):
# When a ZODB connection aborts, it removes registered objects from
# the cache, deletes their jar, deletes their OID, and finally sets
# p_changed to false
inst, jar, OID = self._makeOneWithJar()
del jar._cache[OID]
del inst._p_jar
self.assertEqual(inst._p_jar, None)
del inst._p_oid
self.assertEqual(inst._p_oid, None)
def test_assign_p_jar_w_new_jar(self):
inst, jar, OID = self._makeOneWithJar()
......@@ -164,6 +161,15 @@ class _Persistent_Base(object):
del inst._p_oid
self.assertRaises(ValueError, _test)
def test_del_oid_like_ZODB_abort(self):
# When a ZODB connection aborts, it removes registered objects from
# the cache, deletes their jar, deletes their OID, and finally sets
# p_changed to false
inst, jar, OID = self._makeOneWithJar()
del jar._cache[OID]
del inst._p_oid
self.assertEqual(inst._p_oid, None)
def test_assign_p_serial_w_invalid_type(self):
inst = self._makeOne()
def _test():
......
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