Mike Bayer avatar Mike Bayer committed 831000f

- [bug] Fixed bug which would prevent
OrderingList from being pickleable
[ticket:2454]. Courtesy Jeff Dairiki

Comments (0)

Files changed (3)

     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"/

lib/sqlalchemy/ext/orderinglist.py

         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

test/ext/test_orderinglist.py

-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
             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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.