Carl Meyer avatar Carl Meyer committed 60184d5 Draft

Fix calling create() on a related manager based on PassThroughManager.

Comments (0)

Files changed (3)

 tip (unreleased)
+- Fix calling ``create()`` on a ``RelatedManager`` that subclasses a dynamic
+  ``PassThroughManager``. Thanks SeiryuZ for the report. Fixes GH-24.
 - Add workaround for in
   InheritanceQuerySet to avoid overriding prior calls to
   ``select_related()``. Thanks ivirabyan.


             return queryset_cls(self.model, **kwargs)
         def __reduce__(self):
+            # our pickling support breaks for subclasses (e.g. RelatedManager)
+            if self.__class__ is not _PassThroughManager:
+                return super(_PassThroughManager, self).__reduce__()
             return (
                 (base, queryset_cls),


 class CreatePassThroughManagerTests(TestCase):
     def setUp(self):
         self.dude = Dude.objects.create(name='El Duderino')
-        Spot.objects.create(name='The Crib', owner=self.dude, closed=True,
-                            secure=True)
     def test_reverse_manager(self):
+        Spot.objects.create(
+            name='The Crib', owner=self.dude, closed=True, secure=True)
         self.assertEqual(self.dude.spots_owned.closed().count(), 1)
     def test_related_queryset_pickling(self):
+        Spot.objects.create(
+            name='The Crib', owner=self.dude, closed=True, secure=True)
         qs = self.dude.spots_owned.closed()
         pickled_qs = pickle.dumps(qs)
         unpickled_qs = pickle.loads(pickled_qs)
         self.assertEqual(unpickled_qs.secured().count(), 1)
+    def test_related_manager_create(self):
+        self.dude.spots_owned.create(name='The Crib', closed=True, secure=True)
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
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.