diff options
| -rw-r--r-- | django/db/backends/postgresql/compiler.py | 4 | ||||
| -rw-r--r-- | docs/releases/5.2.10.txt | 6 | ||||
| -rw-r--r-- | docs/releases/6.0.1.txt | 5 | ||||
| -rw-r--r-- | tests/backends/postgresql/test_compilation.py | 10 |
4 files changed, 22 insertions, 3 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))) ] diff --git a/docs/releases/5.2.10.txt b/docs/releases/5.2.10.txt index 0b7ab06d54..6be8f79885 100644 --- a/docs/releases/5.2.10.txt +++ b/docs/releases/5.2.10.txt @@ -4,11 +4,15 @@ Django 5.2.10 release notes *Expected January 6, 2026* -Django 5.2.10 fixes several bugs in 5.2.9. +Django 5.2.10 fixes a data loss bug in Django 5.2 and one bug related to +support for Python 3.14. Bugfixes ======== +* Fixed a bug in Django 5.2 where data exceeding ``max_length`` was silently + truncated by :meth:`.QuerySet.bulk_create` on PostgreSQL (:ticket:`33647`). + * Fixed a bug where management command colorized help (introduced in Python 3.14) ignored the :option:`--no-color` option and the :envvar:`DJANGO_COLORS` setting (:ticket:`36376`). diff --git a/docs/releases/6.0.1.txt b/docs/releases/6.0.1.txt index bb1dfab2c9..a84b1ba6ef 100644 --- a/docs/releases/6.0.1.txt +++ b/docs/releases/6.0.1.txt @@ -4,11 +4,14 @@ Django 6.0.1 release notes *Expected January 6, 2026* -Django 6.0.1 fixes several bugs in 6.0. +Django 6.0.1 fixes one data loss bug in Django 5.2 and several bugs in 6.0. Bugfixes ======== +* Fixed a bug in Django 5.2 where data exceeding ``max_length`` was silently + truncated by :meth:`.QuerySet.bulk_create` on PostgreSQL (:ticket:`33647`). + * Fixed a regression in Django 6.0 where :ttag:`querystring` mishandled multi-value :class:`~django.http.QueryDict` keys, both by only preserving the last value and by incorrectly handling ``None`` values (:ticket:`36783`). diff --git a/tests/backends/postgresql/test_compilation.py b/tests/backends/postgresql/test_compilation.py index 275660607d..a922df3956 100644 --- a/tests/backends/postgresql/test_compilation.py +++ b/tests/backends/postgresql/test_compilation.py @@ -3,6 +3,7 @@ from datetime import date from django.db import connection from django.db.models.expressions import RawSQL +from django.db.utils import DataError from django.test import TestCase from ..models import Article, Reporter, Square @@ -48,3 +49,12 @@ class BulkCreateUnnestTests(TestCase): self.assertEqual( [article.reporter for article in articles], [reporter, reporter] ) + + def test_parametrized_db_type(self): + with self.assertRaises(DataError): + Reporter.objects.bulk_create( + [ + Reporter(), + Reporter(first_name="a" * 31), + ] + ) |
