#35362: ArrayField with nested CharField with a max_length silently truncates
overlong values
-------------------------------------+-------------------------------------
Reporter: Craig de Stigter | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: postgres | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):
* keywords: => postgres
* stage: Unreviewed => Accepted
* version: 5.0 => dev
Comment:
Thank you for the report!
Confirmed behaviour on main, 5.0 and 4.2. Example failing test:
{{{
diff --git a/tests/postgres_tests/test_array.py
b/tests/postgres_tests/test_array.py
index 386a0afa3a..fc932ab19a 100644
--- a/tests/postgres_tests/test_array.py
+++ b/tests/postgres_tests/test_array.py
@@ -148,6 +148,11 @@ class TestSaveLoad(PostgreSQLTestCase):
with self.assertRaises(IntegrityError):
instance.save()
+ def test_char_max_length_exceeded(self):
+ instance = CharArrayModel(field=["a" * 11])
+ with self.assertRaises(IntegrityError):
+ instance.save()
+
def test_nested(self):
instance = NestedIntegerArrayModel(field=[[1, 2], [3, 4]])
instance.save()
}}}
This generates the SQL which has the silent truncation
{{{
INSERT INTO "postgres_tests_chararraymodel" ("field") VALUES
(\'{aaaaaaaaaaa}\'::varchar(10)[]) RETURNING
"postgres_tests_chararraymodel"."id"
}}}
--
Ticket URL: <
https://code.djangoproject.com/ticket/35362#comment:1>