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

This commit is contained in:
Anssi Kääriäinen 2012-10-25 15:27:43 +03:00
parent 11b8712cc7
commit 7de439f32d
2 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -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