summaryrefslogtreecommitdiff
path: root/django/db/models/sql/compiler.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-12-07 20:50:18 +0100
committerGitHub <noreply@github.com>2023-12-07 20:50:18 +0100
commit5b3b791e9046461901df3898be8544e14d91b931 (patch)
treece325771318e61cfe009023039dc147d43acb461 /django/db/models/sql/compiler.py
parent2dca98f4f76e1296b842b183a9287086ec416b58 (diff)
Fixed #35024 -- Fixed model instance creation crash on GeneratedField.output_field with backend converters.
Regression in d9de74141e8a920940f1b91ed0a3ccb835b55729. This is a long standing issue, however it caused a crash of GeneratedFields for all output fields that have backend-specific converters when the RETURNING clause is not supported (MySQL and SQLite < 3.35). That's why severity was exacerbated.
Diffstat (limited to 'django/db/models/sql/compiler.py')
-rw-r--r--django/db/models/sql/compiler.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 7cec040cee..cb559308cd 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -1819,6 +1819,7 @@ class SQLInsertCompiler(SQLCompiler):
)
opts = self.query.get_meta()
self.returning_fields = returning_fields
+ cols = []
with self.connection.cursor() as cursor:
for sql, params in self.as_sql():
cursor.execute(sql, params)
@@ -1829,6 +1830,7 @@ class SQLInsertCompiler(SQLCompiler):
and len(self.query.objs) > 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 = [
@@ -1837,7 +1839,9 @@ class SQLInsertCompiler(SQLCompiler):
self.returning_params,
)
]
+ cols = [field.get_col(opts.db_table) for field in self.returning_fields]
else:
+ cols = [opts.pk.get_col(opts.db_table)]
rows = [
(
self.connection.ops.last_insert_id(
@@ -1847,7 +1851,6 @@ class SQLInsertCompiler(SQLCompiler):
),
)
]
- cols = [field.get_col(opts.db_table) for field in self.returning_fields]
converters = self.get_converters(cols)
if converters:
rows = list(self.apply_converters(rows, converters))