summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Mulder <pmulder@proigia.nl>2016-06-29 11:15:44 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-06-29 17:21:31 -0400
commitfcfff77128174fe5f5e82d2897c5c76df308c8ed (patch)
tree39d957baba905e82344c6b6f58ead4408a39838f
parent7c74d702a9632a8c7264d6972e46985de3fb2487 (diff)
downloadsqlalchemy-fcfff77128174fe5f5e82d2897c5c76df308c8ed.tar.gz
Repair pickling for Properties object
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)
-rw-r--r--doc/build/changelog/changelog_10.rst10
-rw-r--r--lib/sqlalchemy/util/_collections.py4
-rw-r--r--test/base/test_utils.py35
3 files changed, 47 insertions, 2 deletions
diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst
index 7a41731bf..defee6d06 100644
--- a/doc/build/changelog/changelog_10.rst
+++ b/doc/build/changelog/changelog_10.rst
@@ -20,6 +20,16 @@
.. 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
:meth:`.FromClause.count` is pending deprecation for 1.1. This function
diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py
index c29b81f6a..be5d1be44 100644
--- a/lib/sqlalchemy/util/_collections.py
+++ b/lib/sqlalchemy/util/_collections.py
@@ -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:
diff --git a/test/base/test_utils.py b/test/base/test_utils.py
index fcb9a59a3..7e2473dee 100644
--- a/test/base/test_utils.py
+++ b/test/base/test_utils.py
@@ -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())