Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed insert/update handling when no database interaction is required.

Fixed #10205 as part of this.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent bbea457 commit c6a404d1e977cae75345594bf264ca103e1a1d33 @malcolmt malcolmt committed
8 django/db/models/sql/
@@ -2012,9 +2012,11 @@ def execute_sql(self, result_type=MULTI):
iterator over the results if the result_type is MULTI.
result_type is either MULTI (use fetchmany() to retrieve all rows),
- SINGLE (only retrieve a single row), or None (no results expected, but
- the cursor is returned, since it's used by subclasses such as
- InsertQuery).
+ SINGLE (only retrieve a single row), or None. In this last case, the
+ cursor is returned if any query is executed, since it's used by
+ subclasses such as InsertQuery). It's possible, however, that no query
+ is needed, as the filters describe an empty set. In that case, None is
+ returned, to avoid any unnecessary database interaction.
sql, params = self.as_sql()
4 django/db/models/sql/
@@ -117,7 +117,7 @@ def execute_sql(self, result_type=None):
tables, but their rowcounts are not returned).
cursor = super(UpdateQuery, self).execute_sql(result_type)
- rows = cursor.rowcount
+ rows = cursor and cursor.rowcount or 0
del cursor
for query in self.get_related_updates():
@@ -315,7 +315,7 @@ def as_sql(self):
def execute_sql(self, return_id=False):
cursor = super(InsertQuery, self).execute_sql(None)
- if return_id:
+ if return_id and cursor:
return self.connection.ops.last_insert_id(cursor,
6 tests/regressiontests/queries/
@@ -1081,6 +1081,12 @@ def __unicode__(self):
>>> _ = Plaything.objects.create(name="p1")
>>> Plaything.objects.all()
[<Plaything: p1>]
+Bug #10205 -- When bailing out early because of an empty "__in" filter, we need
+to set things up correctly internally so that subqueries can continue properly.
+>>> Tag.objects.filter(name__in=()).update(name="foo")
# In Python 2.3 and the Python 2.6 beta releases, exceptions raised in __len__

0 comments on commit c6a404d

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