#35362: ArrayField with nested CharField with a max_length silently truncates
overlong values
-------------------------------------+-------------------------------------
Reporter: Craig de | Owner: nobody
Stigter |
Type: Bug | Status: new
Component: Database | Version: 5.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
With the following model
{{{
#!python
class TestModel(models.Model):
arrayfield = ArrayField(
models.CharField(max_length=63, blank=False), blank=False,
null=False
)
}}}
Saving an over-long string value into the arrayfield silently truncates
the value:
{{{
#!python
>>> TestModel.objects.create(arrayfield=['a'*100])
<TestModel: TestModel object (1)>
>>> len(TestModel.objects.get().arrayfield[0])
63
}}}
This is probably because the `ArrayField` is casting its values (to
`varchar(63)[]`) during queries for some reason. The
[https://www.postgresql.org/docs/current/datatype-character.html#DATATYPE-
CHARACTER postgres docs] suggest that casting to `varchar(X)` will
truncate strings to X length.
This seems related to #33647 although it's not quite the same situation
since this isn't `bulk_update`
--
Ticket URL: <https://code.djangoproject.com/ticket/35362>
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/0107018ec1f23d7d-dc0986f7-434d-49af-8e29-1a20b507261d-000000%40eu-central-1.amazonses.com.