diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-03-12 05:31:34 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-03-12 05:31:34 +0000 |
| commit | c663e8fbd73ad3ad2f4bd1cdb473b77963c2e352 (patch) | |
| tree | d58c4f928856554a7fcae83232663bc1d3f5ea98 | |
| parent | d4677d4bfbf73110a436037199b6938ce5ea167f (diff) | |
Return last insert ID correctly when the feature is enabled.
This was overlooked when merging the patch from #3460 in r10029.
Thank to Ian Kelly for noticing. Refs #10467.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10034 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/db/models/sql/subqueries.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py index b293ff8925..f421643dc8 100644 --- a/django/db/models/sql/subqueries.py +++ b/django/db/models/sql/subqueries.py @@ -313,9 +313,12 @@ class InsertQuery(Query): def execute_sql(self, return_id=False): cursor = super(InsertQuery, self).execute_sql(None) - if return_id and cursor: - return self.connection.ops.last_insert_id(cursor, - self.model._meta.db_table, self.model._meta.pk.column) + if not (return_id and cursor): + return + if self.connection.features.can_return_id_from_insert: + return cursor.fetchone()[0] + return self.connection.ops.last_insert_id(cursor, + self.model._meta.db_table, self.model._meta.pk.column) def insert_values(self, insert_values, raw_values=False): """ |
