summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/db/models/sql/subqueries.py11
-rw-r--r--tests/regressiontests/model_inheritance_regress/models.py4
2 files changed, 10 insertions, 5 deletions
diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py
index 889188ea51..14af34d7c4 100644
--- a/django/db/models/sql/subqueries.py
+++ b/django/db/models/sql/subqueries.py
@@ -111,14 +111,19 @@ class UpdateQuery(Query):
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):
diff --git a/tests/regressiontests/model_inheritance_regress/models.py b/tests/regressiontests/model_inheritance_regress/models.py
index 9a893924d2..b5c051d5ca 100644
--- a/tests/regressiontests/model_inheritance_regress/models.py
+++ b/tests/regressiontests/model_inheritance_regress/models.py
@@ -271,8 +271,8 @@ True
# (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!")
-0
+1
>>> ArticleWithAuthor.objects.filter(pk=article.pk).update(headline="Oh, no!")
-0
+1
"""}