#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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018ec254b96a-ceee00db-1041-4568-aaf8-d9d59a8b0209-000000%40eu-central-1.amazonses.com.

Reply via email to