From 7d471fe6626de2b36b97ac04086d8ea307be8288 Mon Sep 17 00:00:00 2001 From: Aric Coady Date: Tue, 1 Sep 2015 13:23:06 -0700 Subject: [PATCH] [1.8.x] Refs #20625 -- Fixed custom queryset chaining with values() and values_list(). --- django/db/models/query.py | 4 ++-- docs/releases/1.8.5.txt | 3 +++ tests/custom_managers/tests.py | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/django/db/models/query.py b/django/db/models/query.py index 4163ce9e6d..d76057e9fb 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -937,10 +937,10 @@ class QuerySet(object): using=self.db) def _clone(self, klass=None, setup=False, **kwargs): + base_queryset_class = getattr(self, '_base_queryset_class', self.__class__) if klass is None: klass = self.__class__ - elif not issubclass(self.__class__, klass): - base_queryset_class = getattr(self, '_base_queryset_class', self.__class__) + elif not (issubclass(base_queryset_class, klass) or issubclass(klass, base_queryset_class)): class_bases = (klass, base_queryset_class) class_dict = { '_base_queryset_class': base_queryset_class, diff --git a/docs/releases/1.8.5.txt b/docs/releases/1.8.5.txt index 1141c2c798..5a19a50137 100644 --- a/docs/releases/1.8.5.txt +++ b/docs/releases/1.8.5.txt @@ -36,3 +36,6 @@ Bugfixes * Changed ``Count`` queries to execute ``COUNT(*)`` instead of ``COUNT('*')`` as versions of Django before 1.8 did (:ticket:`25377`). This may fix a performance regression on some databases. + +* Fixed custom queryset chaining with ``values()`` and ``values_list()`` + (:ticket:`20625`). diff --git a/tests/custom_managers/tests.py b/tests/custom_managers/tests.py index 7dc5552e41..b2fe9c51ab 100644 --- a/tests/custom_managers/tests.py +++ b/tests/custom_managers/tests.py @@ -76,6 +76,10 @@ class CustomManagerTests(TestCase): self.assertEqual(list(queryset), [six.text_type("Bugs")]) self.assertEqual(queryset._filter_CustomQuerySet, True) + self.assertIsInstance(queryset.values(), CustomQuerySet) + self.assertIsInstance(queryset.values().values(), CustomQuerySet) + self.assertIsInstance(queryset.values_list().values(), CustomQuerySet) + def test_init_args(self): """ The custom manager __init__() argument has been set.