From 4352e865a75923a0e5036b4e9ba2a8f0bfae3d63 Mon Sep 17 00:00:00 2001 From: Jonas Degrave Date: Thu, 4 Jun 2015 01:13:39 +0200 Subject: [PATCH] Fixed #24911 -- Made BaseManager.get_queryset() allow custom queryset args. --- django/db/models/manager.py | 2 +- tests/custom_managers/models.py | 7 +++++++ tests/custom_managers/tests.py | 9 +++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/django/db/models/manager.py b/django/db/models/manager.py index bedf93a643..a8fd624b35 100644 --- a/django/db/models/manager.py +++ b/django/db/models/manager.py @@ -211,7 +211,7 @@ class BaseManager(object): Returns a new QuerySet object. Subclasses can override this method to easily customize the behavior of the Manager. """ - return self._queryset_class(self.model, using=self._db, hints=self._hints) + return self._queryset_class(model=self.model, using=self._db, hints=self._hints) def all(self): # We can't proxy this method through the `QuerySet` like we do for the diff --git a/tests/custom_managers/models.py b/tests/custom_managers/models.py index 318059a037..5607c11dd0 100644 --- a/tests/custom_managers/models.py +++ b/tests/custom_managers/models.py @@ -66,6 +66,12 @@ class BaseCustomManager(models.Manager): CustomManager = BaseCustomManager.from_queryset(CustomQuerySet) +class CustomInitQuerySet(models.QuerySet): + # QuerySet with an __init__() method that takes an additional argument. + def __init__(self, custom_optional_arg=None, model=None, query=None, using=None, hints=None): + super(CustomInitQuerySet, self).__init__(model=model, query=query, using=using, hints=hints) + + class DeconstructibleCustomManager(BaseCustomManager.from_queryset(CustomQuerySet)): def __init__(self, a, b, c=1, d=2): @@ -99,6 +105,7 @@ class Person(models.Model): custom_queryset_default_manager = CustomQuerySet.as_manager() custom_queryset_custom_manager = CustomManager('hello') + custom_init_queryset_manager = CustomInitQuerySet.as_manager() def __str__(self): return "%s %s" % (self.first_name, self.last_name) diff --git a/tests/custom_managers/tests.py b/tests/custom_managers/tests.py index 0412a423aa..b8acfc906d 100644 --- a/tests/custom_managers/tests.py +++ b/tests/custom_managers/tests.py @@ -597,3 +597,12 @@ class CustomManagersRegressTestCase(TestCase): obj = RelatedModel.objects.get(name="xyzzy") obj.delete() self.assertEqual(len(OneToOneRestrictedModel.plain_manager.all()), 0) + + def test_queryset_with_custom_init(self): + """ + BaseManager.get_queryset() should use kwargs rather than args to allow + custom kwargs (#24911). + """ + qs_custom = Person.custom_init_queryset_manager.all() + qs_default = Person.objects.all() + self.assertQuerysetEqual(qs_custom, qs_default)