[Zodb-checkins] SVN: ZODB/branches/3.6/ PersistentMapping was inadvertently pickling volatile attributes (http://www.zope.org/Collectors/Zope/2052).

Tres Seaver tseaver at palladion.com
Wed Mar 22 10:42:54 EST 2006


Log message for revision 66124:
  PersistentMapping was inadvertently pickling volatile attributes (http://www.zope.org/Collectors/Zope/2052).
  
  

Changed:
  U   ZODB/branches/3.6/NEWS.txt
  U   ZODB/branches/3.6/src/persistent/mapping.py
  U   ZODB/branches/3.6/src/persistent/tests/test_list.py
  U   ZODB/branches/3.6/src/persistent/tests/test_mapping.py

-=-
Modified: ZODB/branches/3.6/NEWS.txt
===================================================================
--- ZODB/branches/3.6/NEWS.txt	2006-03-22 15:42:08 UTC (rev 66123)
+++ ZODB/branches/3.6/NEWS.txt	2006-03-22 15:42:53 UTC (rev 66124)
@@ -132,6 +132,9 @@
 PersistentMapping
 -----------------
 
+- (3.6.1b1) PersistentMapping was inadvertently pickling volatile attributes
+  (http://www.zope.org/Collectors/Zope/2052).
+
 - (3.6b4) ``PersistentMapping`` makes changes by a ``pop()`` method call
   persistent now.
 

Modified: ZODB/branches/3.6/src/persistent/mapping.py
===================================================================
--- ZODB/branches/3.6/src/persistent/mapping.py	2006-03-22 15:42:08 UTC (rev 66123)
+++ ZODB/branches/3.6/src/persistent/mapping.py	2006-03-22 15:42:53 UTC (rev 66124)
@@ -98,8 +98,8 @@
     # actual internal dictionary using the name _container.
 
     def __getstate__(self):
-        state = {}
-        state.update(self.__dict__)
+        state = dict([x for x in self.__dict__.items()
+                        if not x[0].startswith('_v_')])
         state['_container'] = state['data']
         del state['data']
         return state

Modified: ZODB/branches/3.6/src/persistent/tests/test_list.py
===================================================================
--- ZODB/branches/3.6/src/persistent/tests/test_list.py	2006-03-22 15:42:08 UTC (rev 66123)
+++ ZODB/branches/3.6/src/persistent/tests/test_list.py	2006-03-22 15:42:53 UTC (rev 66124)
@@ -11,11 +11,10 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""Test the list interface to PersistentList
+"""Tests for PersistentList
 """
 
 import unittest
-from persistent.list import PersistentList
 
 l0 = []
 l1 = [0]
@@ -23,19 +22,33 @@
 
 class TestPList(unittest.TestCase):
 
+    def _getTargetClass(self):
+        from persistent.list import PersistentList
+        return PersistentList
+
+    def test_volatile_attributes_not_persisted(self):
+        # http://www.zope.org/Collectors/Zope/2052
+        m = self._getTargetClass()()
+        m.foo = 'bar'
+        m._v_baz = 'qux'
+        state = m.__getstate__()
+        self.failUnless('foo' in state)
+        self.failIf('_v_baz' in state)
+
     def testTheWorld(self):
         # Test constructors
-        u = PersistentList()
-        u0 = PersistentList(l0)
-        u1 = PersistentList(l1)
-        u2 = PersistentList(l2)
+        pl = self._getTargetClass()
+        u = pl()
+        u0 = pl(l0)
+        u1 = pl(l1)
+        u2 = pl(l2)
 
-        uu = PersistentList(u)
-        uu0 = PersistentList(u0)
-        uu1 = PersistentList(u1)
-        uu2 = PersistentList(u2)
+        uu = pl(u)
+        uu0 = pl(u0)
+        uu1 = pl(u1)
+        uu2 = pl(u2)
 
-        v = PersistentList(tuple(u))
+        v = pl(tuple(u))
         class OtherList:
             def __init__(self, initlist):
                 self.__data = initlist
@@ -43,8 +56,8 @@
                 return len(self.__data)
             def __getitem__(self, i):
                 return self.__data[i]
-        v0 = PersistentList(OtherList(u0))
-        vv = PersistentList("this is also a sequence")
+        v0 = pl(OtherList(u0))
+        vv = pl("this is also a sequence")
 
         # Test __repr__
         eq = self.assertEqual
@@ -160,7 +173,7 @@
 
         # Test pop
 
-        u = PersistentList([0, -1, 1])
+        u = pl([0, -1, 1])
         u.pop()
         eq(u, [0, -1], "u == [0, -1]")
         u.pop(0)
@@ -200,7 +213,7 @@
 
         # Test sort
 
-        u = PersistentList([1, 0])
+        u = pl([1, 0])
         u.sort()
         eq(u, u2, "u == u2")
 

Modified: ZODB/branches/3.6/src/persistent/tests/test_mapping.py
===================================================================
--- ZODB/branches/3.6/src/persistent/tests/test_mapping.py	2006-03-22 15:42:08 UTC (rev 66123)
+++ ZODB/branches/3.6/src/persistent/tests/test_mapping.py	2006-03-22 15:42:53 UTC (rev 66124)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2005 Zope Corporation and Contributors.
+# Copyright (c) 2006 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -11,37 +11,50 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""Test the mapping interface to PersistentMapping
+"""Test PersistentMapping
 """
 
 import unittest
-from persistent.mapping import PersistentMapping
 
 l0 = {}
 l1 = {0:0}
 l2 = {0:0, 1:1}
 
-class TestPMapping(unittest.TestCase):
+class MappingTests(unittest.TestCase):
 
+    def _getTargetClass(self):
+        from persistent.mapping import PersistentMapping
+        return PersistentMapping
+
+    def test_volatile_attributes_not_persisted(self):
+        # http://www.zope.org/Collectors/Zope/2052
+        m = self._getTargetClass()()
+        m.foo = 'bar'
+        m._v_baz = 'qux'
+        state = m.__getstate__()
+        self.failUnless('foo' in state)
+        self.failIf('_v_baz' in state)
+
     def testTheWorld(self):
         # Test constructors
-        u = PersistentMapping()
-        u0 = PersistentMapping(l0)
-        u1 = PersistentMapping(l1)
-        u2 = PersistentMapping(l2)
+        pm = self._getTargetClass()
+        u = pm()
+        u0 = pm(l0)
+        u1 = pm(l1)
+        u2 = pm(l2)
 
-        uu = PersistentMapping(u)
-        uu0 = PersistentMapping(u0)
-        uu1 = PersistentMapping(u1)
-        uu2 = PersistentMapping(u2)
+        uu = pm(u)
+        uu0 = pm(u0)
+        uu1 = pm(u1)
+        uu2 = pm(u2)
 
         class OtherMapping:
             def __init__(self, initmapping):
                 self.__data = initmapping
             def items(self):
                 return self.__data.items()
-        v0 = PersistentMapping(OtherMapping(u0))
-        vv = PersistentMapping([(0, 0), (1, 1)])
+        v0 = pm(OtherMapping(u0))
+        vv = pm([(0, 0), (1, 1)])
 
         # Test __repr__
         eq = self.assertEqual
@@ -105,7 +118,7 @@
         # Test update
 
         l = {"a":"b"}
-        u = PersistentMapping(l)
+        u = pm(l)
         u.update(u2)
         for i in u:
             self.failUnless(i in l or i in u2, "i in l or i in u2")
@@ -151,10 +164,8 @@
         u2.clear()
         eq(u2, {}, "u2 == {}")
 
-
 def test_suite():
-    return unittest.makeSuite(TestPMapping)
+    return unittest.makeSuite(MappingTests)
 
-if __name__ == "__main__":
-    loader = unittest.TestLoader()
-    unittest.main(testLoader=loader)
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')



More information about the Zodb-checkins mailing list