mirror of
https://github.com/django/django.git
synced 2025-03-13 19:00:45 +00:00
Refs #32433 -- Reallowed calling QuerySet.delete() after distinct().
While values(*field_excluding_pk).distinct() and distinct(*field_excluding_pk) can reduce the number of resulting rows in a way that makes subsequent delete() calls ambiguous standalone .distinct() calls cannot. Since delete() already disallows chain usages with values() the only case that needs to be handled, as originally reported, is when DISTINCT ON is used via distinct(*fields). Refs #32682 which had to resort to subqueries to prevent duplicates in the admin and caused significant performance regressions on MySQL (refs #34639). This partly reverts 6307c3f1a123f5975c73b231e8ac4f115fd72c0d.
This commit is contained in:
parent
95cdf9dc66
commit
28e2077148
@ -1135,8 +1135,8 @@ class QuerySet(AltersData):
|
||||
self._not_support_combined_queries("delete")
|
||||
if self.query.is_sliced:
|
||||
raise TypeError("Cannot use 'limit' or 'offset' with delete().")
|
||||
if self.query.distinct or self.query.distinct_fields:
|
||||
raise TypeError("Cannot call delete() after .distinct().")
|
||||
if self.query.distinct_fields:
|
||||
raise TypeError("Cannot call delete() after .distinct(*fields).")
|
||||
if self._fields is not None:
|
||||
raise TypeError("Cannot call delete() after .values() or .values_list()")
|
||||
|
||||
|
@ -396,10 +396,8 @@ class DeleteTests(TestCase):
|
||||
|
||||
|
||||
class DeleteDistinct(SimpleTestCase):
|
||||
def test_disallowed_delete_distinct(self):
|
||||
msg = "Cannot call delete() after .distinct()."
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
Book.objects.distinct().delete()
|
||||
def test_disallowed_delete_distinct_on(self):
|
||||
msg = "Cannot call delete() after .distinct(*fields)."
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
Book.objects.distinct("id").delete()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user