From ce8deed5cac7273a4a04555445eddda958f2fa5b Mon Sep 17 00:00:00 2001 From: Karl WnW Date: Mon, 2 Nov 2015 16:45:41 +0100 Subject: [PATCH] Fix _clone signature for Django<1.9 InheritanceQuerySetMixin._clone signature conflicts with django ValuesQuerySet._clone code which calls super like this: "c = super(ValuesQuerySet, self)._clone(klass, **kwargs)" --- AUTHORS.rst | 1 + model_utils/managers.py | 5 ++++- model_utils/tests/tests.py | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 62d6561..1776b2b 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -35,4 +35,5 @@ sayane Tony Aldridge Travis Swicegood Trey Hunner +Karl Wan Nan Wo zyegfryed diff --git a/model_utils/managers.py b/model_utils/managers.py index 2247d8a..9392e69 100644 --- a/model_utils/managers.py +++ b/model_utils/managers.py @@ -53,10 +53,13 @@ class InheritanceQuerySetMixin(object): new_qs.subclasses = subclasses return new_qs - def _clone(self, **kwargs): + def _clone(self, klass=None, setup=False, **kwargs): for name in ['subclasses', '_annotated']: if hasattr(self, name): kwargs[name] = getattr(self, name) + if django.VERSION < (1, 9): + kwargs['klass'] = klass + kwargs['setup'] = setup return super(InheritanceQuerySetMixin, self)._clone(**kwargs) def annotate(self, *args, **kwargs): diff --git a/model_utils/tests/tests.py b/model_utils/tests/tests.py index dd40506..d32bf86 100644 --- a/model_utils/tests/tests.py +++ b/model_utils/tests/tests.py @@ -763,6 +763,11 @@ class InheritanceManagerTests(TestCase): set(expected_related_names)) + def test_filter_on_values_queryset(self): + queryset = InheritanceManagerTestChild1.objects.values('id').filter(pk=self.child1.pk) + self.assertEqual(list(queryset), [{'id': self.child1.pk}]) + + class InheritanceManagerUsingModelsTests(TestCase): def setUp(self):