mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #20625 -- Chainable Manager/QuerySet methods.
Additionally this patch solves the orthogonal problem that specialized `QuerySet` like `ValuesQuerySet` didn't inherit from the current `QuerySet` type. This wasn't an issue until now because we didn't officially support custom `QuerySet` but it became necessary with the introduction of this new feature. Thanks aaugustin, akaariai, carljm, charettes, mjtamlyn, shaib and timgraham for the reviews.
This commit is contained in:
parent
8f3aefdec3
commit
31fadc1202
10 changed files with 390 additions and 127 deletions
|
@ -6,6 +6,7 @@ import threading
|
|||
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
|
||||
from django.db import connections, DEFAULT_DB_ALIAS
|
||||
from django.db.models.fields import Field, FieldDoesNotExist
|
||||
from django.db.models.manager import BaseManager
|
||||
from django.db.models.query import QuerySet, EmptyQuerySet, ValuesListQuerySet, MAX_GET_RESULTS
|
||||
from django.test import TestCase, TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature
|
||||
from django.utils import six
|
||||
|
@ -734,3 +735,57 @@ class ConcurrentSaveTests(TransactionTestCase):
|
|||
t.join()
|
||||
a.save()
|
||||
self.assertEqual(Article.objects.get(pk=a.pk).headline, 'foo')
|
||||
|
||||
|
||||
class ManagerTest(TestCase):
|
||||
QUERYSET_PROXY_METHODS = [
|
||||
'none',
|
||||
'count',
|
||||
'dates',
|
||||
'datetimes',
|
||||
'distinct',
|
||||
'extra',
|
||||
'get',
|
||||
'get_or_create',
|
||||
'update_or_create',
|
||||
'create',
|
||||
'bulk_create',
|
||||
'filter',
|
||||
'aggregate',
|
||||
'annotate',
|
||||
'complex_filter',
|
||||
'exclude',
|
||||
'in_bulk',
|
||||
'iterator',
|
||||
'earliest',
|
||||
'latest',
|
||||
'first',
|
||||
'last',
|
||||
'order_by',
|
||||
'select_for_update',
|
||||
'select_related',
|
||||
'prefetch_related',
|
||||
'values',
|
||||
'values_list',
|
||||
'update',
|
||||
'reverse',
|
||||
'defer',
|
||||
'only',
|
||||
'using',
|
||||
'exists',
|
||||
'_update',
|
||||
]
|
||||
|
||||
def test_manager_methods(self):
|
||||
"""
|
||||
This test ensures that the correct set of methods from `QuerySet`
|
||||
are copied onto `Manager`.
|
||||
|
||||
It's particularly useful to prevent accidentally leaking new methods
|
||||
into `Manager`. New `QuerySet` methods that should also be copied onto
|
||||
`Manager` will need to be added to `ManagerTest.QUERYSET_PROXY_METHODS`.
|
||||
"""
|
||||
self.assertEqual(
|
||||
sorted(BaseManager._get_queryset_methods(QuerySet).keys()),
|
||||
sorted(self.QUERYSET_PROXY_METHODS),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue