From 7de439f32d5da88f8a5717717a9e152441708a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Thu, 25 Oct 2012 15:27:43 +0300 Subject: [PATCH] Fixed #19187 -- Raise consistent error from qs.values().delete() --- django/db/models/query.py | 6 ++++++ tests/regressiontests/delete_regress/tests.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/django/db/models/query.py b/django/db/models/query.py index 412cad026f6..dc1ddf16061 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -983,6 +983,12 @@ class ValuesQuerySet(QuerySet): 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 diff --git a/tests/regressiontests/delete_regress/tests.py b/tests/regressiontests/delete_regress/tests.py index ec0d460f17a..f94bb2f20ca 100644 --- a/tests/regressiontests/delete_regress/tests.py +++ b/tests/regressiontests/delete_regress/tests.py @@ -267,6 +267,12 @@ class ProxyDeleteTest(TestCase): 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