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:41:55 -0500 |
| commit | d6ae2ed868e43671afc4d433c3d8f4d27f7eb555 (patch) | |
| tree | 4c363c5e644138f3efa61d810c8e0506b243ec9c /django | |
| parent | 79ab0993d0f2253e10ea638bcefc98ec2d890a47 (diff) | |
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.
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 48d0ccfd9d..9d383b52e8 100644 --- a/django/db/backends/postgresql/compiler.py +++ b/django/db/backends/postgresql/compiler.py @@ -53,7 +53,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))) ] |
