diff --git a/django/db/backends/oracle/operations.py b/django/db/backends/oracle/operations.py index b0b50f7868..a712442f6e 100644 --- a/django/db/backends/oracle/operations.py +++ b/django/db/backends/oracle/operations.py @@ -253,6 +253,7 @@ END; return " DEFERRABLE INITIALLY DEFERRED" def fetch_returned_insert_columns(self, cursor, returning_params): + columns = [] for param in returning_params: value = param.get_value() if value is None or value == []: @@ -264,7 +265,8 @@ END; 'https://code.djangoproject.com/ticket/28859).' ) # cx_Oracle < 7 returns value, >= 7 returns list with single value. - yield value[0] if isinstance(value, list) else value + columns.append(value[0] if isinstance(value, list) else value) + return tuple(columns) def field_cast_sql(self, db_type, internal_type): if db_type and db_type.endswith('LOB'): diff --git a/django/db/models/base.py b/django/db/models/base.py index b2a60629c9..919371540d 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -889,8 +889,9 @@ class Model(metaclass=ModelBase): returning_fields = meta.db_returning_fields results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw) - for result, field in zip(results, returning_fields): - setattr(self, field.attname, result) + if results: + for value, field in zip(results[0], returning_fields): + setattr(self, field.attname, value) return updated def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_update): diff --git a/django/db/models/query.py b/django/db/models/query.py index 5fdee3ff37..1fa7a318c8 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -1249,15 +1249,11 @@ class QuerySet: bulk_return = connections[self.db].features.can_return_rows_from_bulk_insert for item in [objs[i:i + batch_size] for i in range(0, len(objs), batch_size)]: if bulk_return and not ignore_conflicts: - inserted_columns = self._insert( + inserted_rows.extend(self._insert( item, fields=fields, using=self.db, returning_fields=self.model._meta.db_returning_fields, ignore_conflicts=ignore_conflicts, - ) - if isinstance(inserted_columns, list): - inserted_rows.extend(inserted_columns) - else: - inserted_rows.append(inserted_columns) + )) else: self._insert(item, fields=fields, using=self.db, ignore_conflicts=ignore_conflicts) return inserted_rows diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 63ca817355..9433540d7c 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -1385,10 +1385,10 @@ class SQLInsertCompiler(SQLCompiler): return self.connection.ops.fetch_returned_insert_rows(cursor) if self.connection.features.can_return_columns_from_insert: assert len(self.query.objs) == 1 - return self.connection.ops.fetch_returned_insert_columns(cursor, self.returning_params) - return [self.connection.ops.last_insert_id( + return [self.connection.ops.fetch_returned_insert_columns(cursor, self.returning_params)] + return [(self.connection.ops.last_insert_id( cursor, self.query.get_meta().db_table, self.query.get_meta().pk.column - )] + ),)] class SQLDeleteCompiler(SQLCompiler):