diff --git a/django/db/models/query.py b/django/db/models/query.py index 9f9d5a6ce3..15d49b6bac 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -16,7 +16,7 @@ ITER_CHUNK_SIZE = CHUNK_SIZE # Pull into this namespace for backwards compatibility EmptyResultSet = sql.EmptyResultSet -class _QuerySet(object): +class QuerySet(object): "Represents a lazy database lookup for a set of objects" def __init__(self, model=None, query=None): self.model = model @@ -478,12 +478,6 @@ class _QuerySet(object): raise TypeError("Cannot merge querysets of different types ('%s' and '%s'." % (self.__class__.__name__, other.__class__.__name__)) -# Use the backend's QuerySet class if it defines one. Otherwise, use _QuerySet. -if connection.features.uses_custom_queryset: - QuerySet = connection.ops.query_set_class(_QuerySet) -else: - QuerySet = _QuerySet - class ValuesQuerySet(QuerySet): def __init__(self, *args, **kwargs): super(ValuesQuerySet, self).__init__(*args, **kwargs) diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 80ec236edb..d804075926 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -13,6 +13,7 @@ from copy import deepcopy from django.utils.tree import Node from django.utils.datastructures import SortedDict from django.dispatch import dispatcher +from django.db import connection from django.db.models import signals from django.db.models.sql.where import WhereNode, EverythingNode, AND, OR from django.db.models.sql.datastructures import Count @@ -1371,6 +1372,11 @@ class Query(object): return iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)), self.connection.features.empty_fetchmany_value) +# Use the backend's custom Query class if it defines one. Otherwise, use the +# default. +if connection.features.uses_custom_query_class: + Query = connection.ops.query_class(Query) + def get_order_dir(field, default='ASC'): """ Returns the field name and direction for an order specification. For