Commit 82efb484 authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

Fixed #12328 -- Corrected the handling of subqueries with ordering and...

Fixed #12328 -- Corrected the handling of subqueries with ordering and slicing, especially when used in delete subqueries. Thanks to Walter Doekes for the report.

This fixes a feature that isn't available under MySQL and Oracle (Refs #10099).

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12912 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent f92d73fb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ class BaseDatabaseFeatures(object):
    # If True, don't use integer foreign keys referring to, e.g., positive
    # integer primary keys.
    related_fields_match_type = False
    allow_sliced_subqueries = True

class BaseDatabaseOperations(object):
    """
+1 −0
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
    update_can_self_select = False
    allows_group_by_pk = True
    related_fields_match_type = True
    allow_sliced_subqueries = False

class DatabaseOperations(BaseDatabaseOperations):
    compiler_module = "django.db.backends.mysql.compiler"
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
    interprets_empty_strings_as_nulls = True
    uses_savepoints = True
    can_return_id_from_insert = True
    allow_sliced_subqueries = False


class DatabaseOperations(BaseDatabaseOperations):
+6 −3
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ The main QuerySet implementation. This provides the public API for the ORM.
"""

from copy import deepcopy
from itertools import izip

from django.db import connections, router, transaction, IntegrityError
from django.db.models.aggregates import Aggregate
@@ -429,11 +430,13 @@ class QuerySet(object):
        # becoming too long.
        seen_objs = None
        while 1:
            # Collect all the objects to be deleted in this chunk, and all the
            # Collect a chunk of objects to be deleted, and then all the
            # objects that are related to the objects that are to be deleted.
            # The chunking *isn't* done by slicing the del_query because we
            # need to maintain the query cache on del_query (see #12328)
            seen_objs = CollectedObjects(seen_objs)
            for object in del_query[:CHUNK_SIZE]:
                object._collect_sub_objects(seen_objs)
            for i, obj in izip(xrange(CHUNK_SIZE), del_query):
                obj._collect_sub_objects(seen_objs)

            if not seen_objs:
                break
+5 −3
Original line number Diff line number Diff line
@@ -120,12 +120,14 @@ class SQLCompiler(object):
        """
        Perform the same functionality as the as_sql() method, returning an
        SQL string and parameters. However, the alias prefixes are bumped
        beforehand (in a copy -- the current query isn't changed) and any
        ordering is removed.
        beforehand (in a copy -- the current query isn't changed), and any
        ordering is removed if the query is unsliced.

        Used when nesting this query inside another.
        """
        obj = self.query.clone()
        if obj.low_mark == 0 and obj.high_mark is None:
            # If there is no slicing in use, then we can safely drop all ordering
            obj.clear_ordering(True)
        obj.bump_prefix()
        return obj.get_compiler(connection=self.connection).as_sql()
Loading