Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

queryset-refactor: Querysets no longer need to be customised per-back…

…end.

Instead, it's the Query class that is backend-dependent. So make that explicit
in the code (code should refer to sql.Query and they will always get the right
backend-specific class).

This also fixes the main part of #6956, in that the various subclasses of Query
automatically use any custom Query class.

Fixed #6956.


git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7426 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1add6fb36638f064f817d91ff5fb5222555b410c 1 parent c934bee
Malcolm Tredinnick authored April 16, 2008
8  django/db/models/query.py
@@ -16,7 +16,7 @@
16 16
 # Pull into this namespace for backwards compatibility
17 17
 EmptyResultSet = sql.EmptyResultSet
18 18
 
19  
-class _QuerySet(object):
  19
+class QuerySet(object):
20 20
     "Represents a lazy database lookup for a set of objects"
21 21
     def __init__(self, model=None, query=None):
22 22
         self.model = model
@@ -478,12 +478,6 @@ def _merge_sanity_check(self, other):
478 478
             raise TypeError("Cannot merge querysets of different types ('%s' and '%s'."
479 479
                     % (self.__class__.__name__, other.__class__.__name__))
480 480
 
481  
-# Use the backend's QuerySet class if it defines one. Otherwise, use _QuerySet.
482  
-if connection.features.uses_custom_queryset:
483  
-    QuerySet = connection.ops.query_set_class(_QuerySet)
484  
-else:
485  
-    QuerySet = _QuerySet
486  
-
487 481
 class ValuesQuerySet(QuerySet):
488 482
     def __init__(self, *args, **kwargs):
489 483
         super(ValuesQuerySet, self).__init__(*args, **kwargs)
6  django/db/models/sql/query.py
@@ -13,6 +13,7 @@
13 13
 from django.utils.tree import Node
14 14
 from django.utils.datastructures import SortedDict
15 15
 from django.dispatch import dispatcher
  16
+from django.db import connection
16 17
 from django.db.models import signals
17 18
 from django.db.models.sql.where import WhereNode, EverythingNode, AND, OR
18 19
 from django.db.models.sql.datastructures import Count
@@ -1371,6 +1372,11 @@ def execute_sql(self, result_type=MULTI):
1371 1372
         return iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
1372 1373
                 self.connection.features.empty_fetchmany_value)
1373 1374
 
  1375
+# Use the backend's custom Query class if it defines one. Otherwise, use the
  1376
+# default.
  1377
+if connection.features.uses_custom_query_class:
  1378
+    Query = connection.ops.query_class(Query)
  1379
+
1374 1380
 def get_order_dir(field, default='ASC'):
1375 1381
     """
1376 1382
     Returns the field name and direction for an order specification. For

0 notes on commit 1add6fb

Please sign in to comment.
Something went wrong with that request. Please try again.