From 14c8e5227af756a5dea207d8255bc3b3c941340c Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Wed, 4 Mar 2009 05:33:23 +0000 Subject: [PATCH] Changed the row count value returned from update queries in some 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. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9966 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/sql/subqueries.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py index d424e7419c9..385df905699 100644 --- a/django/db/models/sql/subqueries.py +++ b/django/db/models/sql/subqueries.py @@ -113,14 +113,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):