Carl Meyer avatar Carl Meyer committed 208687b Draft

Enable pickling PassThroughManager in Django 1.5.

Comments (0)

Files changed (1)

model_utils/managers.py

 
     @classmethod
     def for_queryset_class(cls, queryset_cls):
-        class _PassThroughManager(cls):
-            def __init__(self):
-                return super(_PassThroughManager, self).__init__()
+        return create_pass_through_manager_for_queryset_class(cls, queryset_cls)
 
-            def get_query_set(self):
-                kwargs = {}
-                if hasattr(self, "_db"):
-                    kwargs["using"] = self._db
-                return queryset_cls(self.model, **kwargs)
 
-        return _PassThroughManager
+def create_pass_through_manager_for_queryset_class(base, queryset_cls):
+    class _PassThroughManager(base):
+        def __init__(self):
+            return super(_PassThroughManager, self).__init__()
+
+        def get_query_set(self):
+            kwargs = {}
+            if hasattr(self, "_db"):
+                kwargs["using"] = self._db
+            return queryset_cls(self.model, **kwargs)
+
+        def __reduce__(self):
+            return (
+                unpickle_pass_through_manager_for_queryset_class,
+                (base, queryset_cls),
+                self.__dict__,
+                )
+
+    return _PassThroughManager
+
+
+def unpickle_pass_through_manager_for_queryset_class(base, queryset_cls):
+    cls = create_pass_through_manager_for_queryset_class(base, queryset_cls)
+    return cls.__new__(cls)
 
 
 def manager_from(*mixins, **kwds):
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.