Commits

Anonymous committed c3f9f38

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

Comments (0)

Files changed (2)

django/db/models/query.py

         for row in self.query.get_compiler(self.db).results_iter():
             yield dict(zip(names, row))
 
+    def delete(self):
+        # values().delete() doesn't work currently - make sure it raises an
+        # user friendly error.
+        raise TypeError("Queries with .values() or .values_list() applied "
+                        "can't be deleted")
+
     def _setup_query(self):
         """
         Constructs the field_names list that the values query will be

tests/regressiontests/delete_regress/tests.py

 
         self.assertEqual(len(FooFileProxy.objects.all()), 0)
 
+    def test_19187_values(self):
+        with self.assertRaises(TypeError):
+            Image.objects.values().delete()
+        with self.assertRaises(TypeError):
+            Image.objects.values_list().delete()
+
 class Ticket19102Tests(TestCase):
     """
     Test different queries which alter the SELECT clause of the query. We