mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Fixed #19102 -- Fixed fast-path delete for modified SELECT clause cases
There was a bug introduced in #18676 which caused fast-path deletes implemented as "DELETE WHERE pk IN <subquery>" to fail if the SELECT clause contained additional stuff (for example extra() and annotate()). Thanks to Trac alias pressureman for spotting this regression.
This commit is contained in:
@@ -431,13 +431,9 @@ class Query(object):
|
||||
|
||||
def has_results(self, using):
|
||||
q = self.clone()
|
||||
q.clear_select_clause()
|
||||
q.add_extra({'a': 1}, None, None, None, None, None)
|
||||
q.select = []
|
||||
q.select_fields = []
|
||||
q.default_cols = False
|
||||
q.select_related = False
|
||||
q.set_extra_mask(('a',))
|
||||
q.set_aggregate_mask(())
|
||||
q.set_extra_mask(['a'])
|
||||
q.clear_ordering(True)
|
||||
q.set_limits(high=1)
|
||||
compiler = q.get_compiler(using=using)
|
||||
@@ -1626,6 +1622,17 @@ class Query(object):
|
||||
"""
|
||||
return not self.low_mark and self.high_mark is None
|
||||
|
||||
def clear_select_clause(self):
|
||||
"""
|
||||
Removes all fields from SELECT clause.
|
||||
"""
|
||||
self.select = []
|
||||
self.select_fields = []
|
||||
self.default_cols = False
|
||||
self.select_related = False
|
||||
self.set_extra_mask(())
|
||||
self.set_aggregate_mask(())
|
||||
|
||||
def clear_select_fields(self):
|
||||
"""
|
||||
Clears the list of fields to select (but not extra_select columns).
|
||||
|
||||
@@ -70,8 +70,9 @@ class DeleteQuery(Query):
|
||||
self.delete_batch(values, using)
|
||||
return
|
||||
else:
|
||||
values = innerq
|
||||
innerq.clear_select_clause()
|
||||
innerq.select = [(self.get_initial_alias(), pk.column)]
|
||||
values = innerq
|
||||
where = self.where_class()
|
||||
where.add((Constraint(None, pk.column, pk), 'in', values), AND)
|
||||
self.where = where
|
||||
@@ -237,11 +238,8 @@ class DateQuery(Query):
|
||||
% field.name
|
||||
alias = result[3][-1]
|
||||
select = Date((alias, field.column), lookup_type)
|
||||
self.clear_select_clause()
|
||||
self.select = [select]
|
||||
self.select_fields = [None]
|
||||
self.select_related = False # See #7097.
|
||||
self.aggregates = SortedDict() # See 18056.
|
||||
self.set_extra_mask([])
|
||||
self.distinct = True
|
||||
self.order_by = order == 'ASC' and [1] or [-1]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user