Skip to content

Commit cf1b684

Browse files
Fixed #12142 -- EmptyQuerySet.update() no longer updates all rows in the database
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12171 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 0683a79 commit cf1b684

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

django/db/models/query.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,12 @@ def only(self, *fields):
10891089
"""
10901090
return self
10911091

1092+
def update(self, **kwargs):
1093+
"""
1094+
Don't update anything.
1095+
"""
1096+
return 0
1097+
10921098
# EmptyQuerySet is always an empty result in where-clauses (and similar
10931099
# situations).
10941100
value_annotation = False

tests/modeltests/lookup/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ def __unicode__(self):
295295
[]
296296
>>> Article.objects.none().count()
297297
0
298+
>>> Article.objects.none().update(headline="This should not take effect")
299+
0
298300
>>> [article for article in Article.objects.none().iterator()]
299301
[]
300302

0 commit comments

Comments
 (0)