Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #19187 -- Raise consistent error from qs.values().delete()

  • Loading branch information...
commit 7de439f32d5da88f8a5717717a9e152441708a9f 1 parent 11b8712
Anssi Kääriäinen authored
6  django/db/models/query.py
@@ -983,6 +983,12 @@ def iterator(self):
983 983
         for row in self.query.get_compiler(self.db).results_iter():
984 984
             yield dict(zip(names, row))
985 985
 
  986
+    def delete(self):
  987
+        # values().delete() doesn't work currently - make sure it raises an
  988
+        # user friendly error.
  989
+        raise TypeError("Queries with .values() or .values_list() applied "
  990
+                        "can't be deleted")
  991
+
986 992
     def _setup_query(self):
987 993
         """
988 994
         Constructs the field_names list that the values query will be
6  tests/regressiontests/delete_regress/tests.py
@@ -267,6 +267,12 @@ def test_delete_proxy_pair(self):
267 267
 
268 268
         self.assertEqual(len(FooFileProxy.objects.all()), 0)
269 269
 
  270
+    def test_19187_values(self):
  271
+        with self.assertRaises(TypeError):
  272
+            Image.objects.values().delete()
  273
+        with self.assertRaises(TypeError):
  274
+            Image.objects.values_list().delete()
  275
+
270 276
 class Ticket19102Tests(TestCase):
271 277
     """
272 278
     Test different queries which alter the SELECT clause of the query. We

0 notes on commit 7de439f

Please sign in to comment.
Something went wrong with that request. Please try again.