Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

[1.0.X] Changed the row count value returned from update queries in s…

…ome cases.

If an update only affected an ancestor model (not the child), we were
returning 0 for the number of rows updated. This could have been
misleading if the value is used to detect an update occuring. So we now
return the rowcount from the first non-trivial query that is executed
(if any). Still a slight compromise, but better than what we had.

Backport of r9966 from trunk (turns out this *is* a bugfix, since the returned
rowcount is used in

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent f1c9080 commit b57d86f226ca4fded1fc8bf6300450fb6a0566c1 @malcolmt malcolmt committed
11 django/db/models/sql/
@@ -111,14 +111,19 @@ def clone(self, klass=None, **kwargs):
def execute_sql(self, result_type=None):
Execute the specified update. Returns the number of rows affected by
- the primary update query (there could be other updates on related
- tables, but their rowcounts are not returned).
+ the primary update query. The "primary update query" is the first
+ non-empty query that is executed. Row counts for any subsequent,
+ related queries are not available.
cursor = super(UpdateQuery, self).execute_sql(result_type)
rows = cursor and cursor.rowcount or 0
+ is_empty = cursor is None
del cursor
for query in self.get_related_updates():
- query.execute_sql(result_type)
+ aux_rows = query.execute_sql(result_type)
+ if is_empty:
+ rows = aux_rows
+ is_empty = False
return rows
def as_sql(self):
4 tests/regressiontests/model_inheritance_regress/
@@ -271,8 +271,8 @@ class QualityControl(Evaluation):
# (regression test for #10362).
>>> article = ArticleWithAuthor.objects.create(author="fred", headline="Hey there!", pub_date = datetime.datetime(2009, 3, 1, 8, 0, 0))
>>> ArticleWithAuthor.objects.filter(author="fred").update(headline="Oh, no!")
>>> ArticleWithAuthor.objects.filter("Oh, no!")

0 comments on commit b57d86f

Please sign in to comment.
Something went wrong with that request. Please try again.