From eef3ea847e12f23db9a0af8efdc9543f24b780c4 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Thu, 9 Jan 2020 11:10:25 +0100 Subject: [PATCH] Fixed #31148 -- Added error messages on update()/delete() operations following union(), intersection(), and difference(). --- django/db/models/query.py | 2 ++ tests/queries/test_qs_combinators.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/django/db/models/query.py b/django/db/models/query.py index 38c13584d1..f8be008a62 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -711,6 +711,7 @@ class QuerySet: def delete(self): """Delete the records in the current QuerySet.""" + self._not_support_combined_queries('delete') assert not self.query.is_sliced, \ "Cannot use 'limit' or 'offset' with delete." @@ -756,6 +757,7 @@ class QuerySet: Update all elements in the current QuerySet, setting all the given fields to the appropriate values. """ + self._not_support_combined_queries('update') assert not self.query.is_sliced, \ "Cannot update a query once a slice has been taken." self._for_write = True diff --git a/tests/queries/test_qs_combinators.py b/tests/queries/test_qs_combinators.py index 668d5e6ad6..71309ecf1b 100644 --- a/tests/queries/test_qs_combinators.py +++ b/tests/queries/test_qs_combinators.py @@ -272,12 +272,14 @@ class QuerySetSetOperationTests(TestCase): for operation in ( 'annotate', 'defer', + 'delete', 'exclude', 'extra', 'filter', 'only', 'prefetch_related', 'select_related', + 'update', ): with self.subTest(combinator=combinator, operation=operation): with self.assertRaisesMessage(