mirror of
https://github.com/django/django.git
synced 2024-12-22 09:05:43 +00:00
Fixed #32433 -- Added error message on QuerySet.delete() following distinct().
This commit is contained in:
parent
4e8ecf0cb6
commit
6307c3f1a1
1
AUTHORS
1
AUTHORS
@ -274,6 +274,7 @@ answer newbie questions, and generally made Django that much better:
|
||||
dusk@woofle.net
|
||||
Dustyn Gibson <miigotu@gmail.com>
|
||||
Ed Morley <https://github.com/edmorley>
|
||||
Egidijus Macijauskas <e.macijauskas@outlook.com>
|
||||
eibaan@gmail.com
|
||||
elky <http://elky.me/>
|
||||
Emmanuelle Delescolle <https://github.com/nanuxbe>
|
||||
|
@ -724,6 +724,8 @@ class QuerySet:
|
||||
assert not self.query.is_sliced, \
|
||||
"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._fields is not None:
|
||||
raise TypeError("Cannot call delete() after .values() or .values_list()")
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
import datetime
|
||||
|
||||
from django.db import connection, models, transaction
|
||||
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
|
||||
from django.test import (
|
||||
SimpleTestCase, TestCase, TransactionTestCase, skipUnlessDBFeature,
|
||||
)
|
||||
|
||||
from .models import (
|
||||
Award, AwardNote, Book, Child, Contact, Eaten, Email, File, Food, FooFile,
|
||||
@ -352,3 +354,12 @@ class DeleteTests(TestCase):
|
||||
self.assertEqual(researcher1.secondary_contact, contact2)
|
||||
self.assertEqual(researcher2.primary_contact, contact2)
|
||||
self.assertIsNone(researcher2.secondary_contact)
|
||||
|
||||
|
||||
class DeleteDistinct(SimpleTestCase):
|
||||
def test_disallowed_delete_distinct(self):
|
||||
msg = 'Cannot call delete() after .distinct().'
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
Book.objects.distinct().delete()
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
Book.objects.distinct('id').delete()
|
||||
|
Loading…
Reference in New Issue
Block a user