diff options
Diffstat (limited to 'django/db/models/sql/compiler.py')
| -rw-r--r-- | django/db/models/sql/compiler.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index f72ba907ad..73dfa5b87c 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -1890,7 +1890,7 @@ class SQLInsertCompiler(SQLCompiler): result.append(on_conflict_suffix_sql) # Skip empty r_sql to allow subclasses to customize behavior for # 3rd party backends. Refs #19096. - r_sql, self.returning_params = self.connection.ops.return_insert_columns( + r_sql, self.returning_params = self.connection.ops.returning_columns( self.returning_fields ) if r_sql: @@ -1925,20 +1925,16 @@ class SQLInsertCompiler(SQLCompiler): cursor.execute(sql, params) if not self.returning_fields: return [] + obj_len = len(self.query.objs) if ( self.connection.features.can_return_rows_from_bulk_insert - and len(self.query.objs) > 1 + and obj_len > 1 + ) or ( + self.connection.features.can_return_columns_from_insert and obj_len == 1 ): - rows = self.connection.ops.fetch_returned_insert_rows(cursor) - cols = [field.get_col(opts.db_table) for field in self.returning_fields] - elif self.connection.features.can_return_columns_from_insert: - assert len(self.query.objs) == 1 - rows = [ - self.connection.ops.fetch_returned_insert_columns( - cursor, - self.returning_params, - ) - ] + rows = self.connection.ops.fetch_returned_rows( + cursor, self.returning_params + ) cols = [field.get_col(opts.db_table) for field in self.returning_fields] elif returning_fields and isinstance( returning_field := returning_fields[0], AutoField |
