summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-04-01 11:01:56 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-04-01 11:01:56 -0400
commit2563b33453dee1b55500f13421b7b50ba367a504 (patch)
tree24de4704b64d496297873bd84b9a1ca7ae658839
parent45046367f34ee2dadb98024b0f2b05248459f978 (diff)
downloadsqlalchemy-2563b33453dee1b55500f13421b7b50ba367a504.tar.gz
- [bug] Fixed bug which would prevent
OrderingList from being pickleable [ticket:2454]. Courtesy Jeff Dairiki
-rw-r--r--CHANGES4
-rw-r--r--lib/sqlalchemy/ext/orderinglist.py14
-rw-r--r--test/ext/test_orderinglist.py32
3 files changed, 46 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index 2dcceddb6..727e7235f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -24,6 +24,10 @@ CHANGES
and joins, particularly when using
column_property(). [ticket:2453]
+ - [bug] Fixed bug which would prevent
+ OrderingList from being pickleable
+ [ticket:2454]. Courtesy Jeff Dairiki
+
- postgresql
- [feature] Added new for_update/with_lockmode()
options for Postgresql: for_update="read"/
diff --git a/lib/sqlalchemy/ext/orderinglist.py b/lib/sqlalchemy/ext/orderinglist.py
index 97be329e9..0a27ee309 100644
--- a/lib/sqlalchemy/ext/orderinglist.py
+++ b/lib/sqlalchemy/ext/orderinglist.py
@@ -314,9 +314,23 @@ class OrderingList(list):
self._reorder()
# end Py2K
+ def __reduce__(self):
+ return _reconstitute, (self.__class__, self.__dict__, list(self))
+
for func_name, func in locals().items():
if (util.callable(func) and func.func_name == func_name and
not func.__doc__ and hasattr(list, func_name)):
func.__doc__ = getattr(list, func_name).__doc__
del func_name, func
+def _reconstitute(cls, dict_, items):
+ """ Reconstitute an ``OrderingList``.
+
+ This is the adjoint to ``OrderingList.__reduce__()``. It is used for
+ unpickling ``OrderingList``\\s
+
+ """
+ obj = cls.__new__(cls)
+ obj.__dict__.update(dict_)
+ list.extend(obj, items)
+ return obj
diff --git a/test/ext/test_orderinglist.py b/test/ext/test_orderinglist.py
index dfeac5c3e..0b7d4328e 100644
--- a/test/ext/test_orderinglist.py
+++ b/test/ext/test_orderinglist.py
@@ -1,8 +1,10 @@
-from sqlalchemy import *
-from sqlalchemy.orm import *
-from sqlalchemy.ext.orderinglist import *
+from sqlalchemy import Integer, ForeignKey, String, MetaData
+from sqlalchemy.orm import relationship, mapper, create_session
+from sqlalchemy.ext.orderinglist import ordering_list
from test.lib.testing import eq_
-from test.lib import *
+from test.lib import fixtures, testing
+from test.lib.schema import Table, Column
+from test.lib.util import picklers
metadata = None
@@ -407,3 +409,25 @@ class OrderingListTest(fixtures.TestBase):
self.assert_(alpha[li].position == pos)
+ def test_picklability(self):
+ from sqlalchemy.ext.orderinglist import OrderingList
+
+ olist = OrderingList('order', reorder_on_append=True)
+ olist.append(DummyItem())
+
+ for loads, dumps in picklers():
+ pck = dumps(olist)
+ copy = loads(pck)
+
+ self.assert_(copy == olist)
+ self.assert_(copy.__dict__ == olist.__dict__)
+
+class DummyItem(object):
+ def __init__(self, order=None):
+ self.order = order
+
+ def __eq__(self, other):
+ return self.order == other.order
+
+ def __ne__(self, other):
+ return not (self == other)