[Zodb-checkins] SVN: ZODB/branches/tseaver-python_picklecache-2/src/persistent/ Allow deleting _p_oid only if jar is None.

Tres Seaver tseaver at palladion.com
Wed Feb 16 00:04:38 EST 2011


Log message for revision 120369:
  Allow deleting _p_oid only if jar is None.

Changed:
  U   ZODB/branches/tseaver-python_picklecache-2/src/persistent/pyPersistence.py
  U   ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_pyPersistence.py

-=-
Modified: ZODB/branches/tseaver-python_picklecache-2/src/persistent/pyPersistence.py
===================================================================
--- ZODB/branches/tseaver-python_picklecache-2/src/persistent/pyPersistence.py	2011-02-16 05:04:36 UTC (rev 120368)
+++ ZODB/branches/tseaver-python_picklecache-2/src/persistent/pyPersistence.py	2011-02-16 05:04:37 UTC (rev 120369)
@@ -103,13 +103,14 @@
         if value is not None:
             if not isinstance(value, OID_TYPE):
                 raise ValueError('Invalid OID type: %s' % value)
-        if self.__oid is not None:
-            raise ValueError('Already assigned an OID')
+        if self.__jar is not None and self.__oid is not None:
+            raise ValueError('Already assigned an OID by our jar')
         self.__oid = value
 
     def _del_oid(self):
-        if self.__oid is not None:
-            raise ValueError('Cannot delete OID once assigned')
+        if self.__jar is not None:
+            raise ValueError('Cannot delete OID once assigned to a jar')
+        self.__oid = None
 
     _p_oid = property(_get_oid, _set_oid, _del_oid)
 

Modified: ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_pyPersistence.py
===================================================================
--- ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_pyPersistence.py	2011-02-16 05:04:36 UTC (rev 120368)
+++ ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_pyPersistence.py	2011-02-16 05:04:37 UTC (rev 120369)
@@ -108,24 +108,35 @@
         self.assertEqual(inst._p_oid, OID)
         inst._p_oid = OID  # reassign only same OID
 
-    def test_assign_p_oid_w_new_oid(self):
+    def test_assign_p_oid_w_new_oid_wo_jar(self):
         OID1 = '1' * 8
         OID2 = '2' * 8
         inst = self._makeOne()
         inst._p_oid = OID1
+        inst._p_oid = OID2
+        self.assertEqual(inst._p_oid, OID2)
+
+    def test_assign_p_oid_w_new_oid_w_jar(self):
+        OID1 = '1' * 8
+        OID2 = '2' * 8
+        inst = self._makeOne()
+        inst._p_oid = OID1
+        inst._p_jar = self._makeJar()
         def _test():
             inst._p_oid = OID2
         self.assertRaises(ValueError, _test)
 
-    def test_delete_p_oid_wo_real_oid(self):
+    def test_delete_p_oid_wo_jar(self):
         inst = self._makeOne()
+        inst._p_oid = '\x01' * 8
         del inst._p_oid
         self.assertEqual(inst._p_oid, None)
 
-    def test_delete_p_oid_w_real_oid(self):
+    def test_delete_p_oid_w_jar(self):
         OID = '1' * 8
         inst = self._makeOne()
         inst._p_oid = OID
+        inst._p_jar = self._makeJar()
         def _test():
             del inst._p_oid
         self.assertRaises(ValueError, _test)



More information about the Zodb-checkins mailing list