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

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


Log message for revision 120368:
  Allow deleting _p_oid only if 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:35 UTC (rev 120367)
+++ ZODB/branches/tseaver-python_picklecache-2/src/persistent/pyPersistence.py	2011-02-16 05:04:36 UTC (rev 120368)
@@ -107,8 +107,12 @@
             raise ValueError('Already assigned an OID')
         self.__oid = value
 
-    _p_oid = property(_get_oid, _set_oid)
+    def _del_oid(self):
+        if self.__oid is not None:
+            raise ValueError('Cannot delete OID once assigned')
 
+    _p_oid = property(_get_oid, _set_oid, _del_oid)
+
     # _p_serial:  see IPersistent.
     def _get_serial(self):
         if self.__serial is not None:

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:35 UTC (rev 120367)
+++ ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_pyPersistence.py	2011-02-16 05:04:36 UTC (rev 120368)
@@ -117,6 +117,19 @@
             inst._p_oid = OID2
         self.assertRaises(ValueError, _test)
 
+    def test_delete_p_oid_wo_real_oid(self):
+        inst = self._makeOne()
+        del inst._p_oid
+        self.assertEqual(inst._p_oid, None)
+
+    def test_delete_p_oid_w_real_oid(self):
+        OID = '1' * 8
+        inst = self._makeOne()
+        inst._p_oid = OID
+        def _test():
+            del inst._p_oid
+        self.assertRaises(ValueError, _test)
+
     def test_assign_p_serial_w_invalid_serial(self):
         inst = self._makeOne()
         def _test():



More information about the Zodb-checkins mailing list