mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #35024 -- Fixed model instance creation crash on GeneratedField.output_field with backend converters.
Regression in d9de74141e.
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.
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user