Code

Ticket #12142: django_emptyqueryset_withtest.diff

File django_emptyqueryset_withtest.diff, 797 bytes (added by cwebber, 4 years ago)

Updated "patch with overriden update() returning 0", with a test

Line 
1diff --git a/django/db/models/query.py b/django/db/models/query.py
2index 0b57b1e..39c754f 100644
3--- a/django/db/models/query.py
4+++ b/django/db/models/query.py
5@@ -1001,6 +1001,9 @@ class EmptyQuerySet(QuerySet):
6     def count(self):
7         return 0
8 
9+    def update(self, **kwargs):
10+        return 0
11+
12     def delete(self):
13         pass
14 
15diff --git a/tests/modeltests/lookup/models.py b/tests/modeltests/lookup/models.py
16index 512ffd7..6c86dad 100644
17--- a/tests/modeltests/lookup/models.py
18+++ b/tests/modeltests/lookup/models.py
19@@ -295,6 +295,8 @@ DoesNotExist: Article matching query does not exist.
20 []
21 >>> Article.objects.none().count()
22 0
23+>>> Article.objects.none().update(headline="Don't update me bro")
24+0
25 >>> [article for article in Article.objects.none().iterator()]
26 []
27