]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Repair pickling for Properties object
authorPieter Mulder <pmulder@proigia.nl>
Wed, 29 Jun 2016 15:15:44 +0000 (11:15 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 29 Jun 2016 21:21:31 +0000 (17:21 -0400)
Fixed bug whereby the ``__getstate__`` / ``__setstate__``
methods for sqlalchemy.util.Properties were
non-working due to the transition in the 1.0 series to ``__slots__``.
The issue potentially impacted some third-party applications.
Pull request courtesy Pieter Mulder.

Fixes: #3728
Change-Id: I01ebd425bbfe145747fea2edd0d2d412c74fd84d
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/286
(cherry picked from commit cab57e9bab04fbdea44690c08dff379a29eaab32)

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/util/_collections.py
test/base/test_utils.py

index 7a41731bff0eac7d97b9dad99c5b8744abba6d11..defee6d06e0cbc23cd2d2abdca7ac02111be1ae5 100644 (file)
 .. changelog::
     :version: 1.0.14
 
+    .. change::
+        :tags: bug, sql
+        :tickets: 3728
+
+        Fixed bug whereby the ``__getstate__`` / ``__setstate__``
+        methods for sqlalchemy.util.Properties were
+        non-working due to the transition in the 1.0 series to ``__slots__``.
+        The issue potentially impacted some third-party applications.
+        Pull request courtesy Pieter Mulder.
+
     .. change::
         :tags: bug, sql
         :tickets: 3724
index c29b81f6a1007626cfdd0a3beeba4f207fb1da09..be5d1be442d242ee59a4b465e2792ce6e8e2682d 100644 (file)
@@ -200,10 +200,10 @@ class Properties(object):
         self._data[key] = obj
 
     def __getstate__(self):
-        return {'_data': self.__dict__['_data']}
+        return {'_data': self._data}
 
     def __setstate__(self, state):
-        self.__dict__['_data'] = state['_data']
+        object.__setattr__(self, '_data', state['_data'])
 
     def __getattr__(self, key):
         try:
index fcb9a59a3b9604b846973915dc09dc6a0d5991e9..7e2473deed88d429907338b521a60970b1f73df3 100644 (file)
@@ -2256,3 +2256,38 @@ class TestClassProperty(fixtures.TestBase):
         eq_(B.something, {'foo': 1, 'bazz': 2})
 
 
+class TestProperties(fixtures.TestBase):
+
+    def test_pickle(self):
+        data = {'hello': 'bla'}
+        props = util.Properties(data)
+
+        for loader, dumper in picklers():
+            s = dumper(props)
+            p = loader(s)
+
+            eq_(props._data, p._data)
+            eq_(props.keys(), p.keys())
+
+    def test_pickle_immuatbleprops(self):
+        data = {'hello': 'bla'}
+        props = util.Properties(data).as_immutable()
+
+        for loader, dumper in picklers():
+            s = dumper(props)
+            p = loader(s)
+
+            eq_(props._data, p._data)
+            eq_(props.keys(), p.keys())
+
+    def test_pickle_orderedprops(self):
+        data = {'hello': 'bla'}
+        props = util.OrderedProperties()
+        props.update(data)
+
+        for loader, dumper in picklers():
+            s = dumper(props)
+            p = loader(s)
+
+            eq_(props._data, p._data)
+            eq_(props.keys(), p.keys())