diff options
| author | Simon Charette <charette.s@gmail.com> | 2025-12-23 01:25:56 -0500 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-12-31 10:42:58 -0500 |
| commit | 764af478be8c25c186d27031c50c9a1d0697781b (patch) | |
| tree | a0af4c766761d9424b6796ca2f5ac6427d6d6967 /django | |
| parent | b7b5465b1c026dda7de646fca15ca1e97886d021 (diff) | |
[6.0.x] Refs #33647 -- Fixed silent data truncation in bulk_create on Postgres.
Regression in a16eedcf9c69d8a11d94cac1811018c5b996d491.
The UNNEST strategy is affected by the same problem bulk_update has wrt/
to silent data truncation due to its usage of db_type which always returns
a parametrized subtype.
Backport of d6ae2ed868e43671afc4d433c3d8f4d27f7eb555 from main.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/postgresql/compiler.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/django/db/backends/postgresql/compiler.py b/django/db/backends/postgresql/compiler.py index 08d78e333a..81d291cf36 100644 --- a/django/db/backends/postgresql/compiler.py +++ b/django/db/backends/postgresql/compiler.py @@ -62,7 +62,9 @@ class SQLInsertCompiler(BaseSQLInsertCompiler): or any(any(hasattr(value, "as_sql") for value in row) for row in value_rows) ): return super().assemble_as_sql(fields, value_rows) - db_types = [field.db_type(self.connection) for field in fields] + # Manually remove parameters from `db_type` to ensure no data + # truncation takes place (e.g. varchar[] instead of varchar(50)[]). + db_types = [field.db_type(self.connection).split("(")[0] for field in fields] return InsertUnnest(["(%%s)::%s[]" % db_type for db_type in db_types]), [ list(map(list, zip(*value_rows))) ] |
