mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #36683 -- Added error message on QuerySet.update() following distinct(*fields).
This commit is contained in:
committed by
Jacob Walls
parent
3ff32c50d1
commit
4744e9939b
1
AUTHORS
1
AUTHORS
@@ -707,6 +707,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
Matt Dennenbaum
|
Matt Dennenbaum
|
||||||
Matthew Flanagan <https://wadofstuff.blogspot.com/>
|
Matthew Flanagan <https://wadofstuff.blogspot.com/>
|
||||||
Matthew Schinckel <matt@schinckel.net>
|
Matthew Schinckel <matt@schinckel.net>
|
||||||
|
Matthew Shirley <matt@mattshirley.net>
|
||||||
Matthew Somerville <matthew-django@dracos.co.uk>
|
Matthew Somerville <matthew-django@dracos.co.uk>
|
||||||
Matthew Tretter <m@tthewwithanm.com>
|
Matthew Tretter <m@tthewwithanm.com>
|
||||||
Matthew Wilkes <matt@matthewwilkes.name>
|
Matthew Wilkes <matt@matthewwilkes.name>
|
||||||
|
|||||||
@@ -1338,6 +1338,8 @@ class QuerySet(AltersData):
|
|||||||
self._not_support_combined_queries("update")
|
self._not_support_combined_queries("update")
|
||||||
if self.query.is_sliced:
|
if self.query.is_sliced:
|
||||||
raise TypeError("Cannot update a query once a slice has been taken.")
|
raise TypeError("Cannot update a query once a slice has been taken.")
|
||||||
|
if self.query.distinct_fields:
|
||||||
|
raise TypeError("Cannot call update() after .distinct(*fields).")
|
||||||
self._for_write = True
|
self._for_write = True
|
||||||
query = self.query.chain(sql.UpdateQuery)
|
query = self.query.chain(sql.UpdateQuery)
|
||||||
query.add_update_values(kwargs)
|
query.add_update_values(kwargs)
|
||||||
|
|||||||
@@ -178,3 +178,9 @@ class DistinctOnTests(TestCase):
|
|||||||
.order_by("nAmEAlIaS")
|
.order_by("nAmEAlIaS")
|
||||||
)
|
)
|
||||||
self.assertSequenceEqual(qs, [self.p1_o1, self.p2_o1, self.p3_o1])
|
self.assertSequenceEqual(qs, [self.p1_o1, self.p2_o1, self.p3_o1])
|
||||||
|
|
||||||
|
def test_disallowed_update_distinct_on(self):
|
||||||
|
qs = Staff.objects.distinct("organisation").order_by("organisation")
|
||||||
|
msg = "Cannot call update() after .distinct(*fields)."
|
||||||
|
with self.assertRaisesMessage(TypeError, msg):
|
||||||
|
qs.update(name="p4")
|
||||||
|
|||||||
Reference in New Issue
Block a user