#35946: Postgres ArrayField should convert values when given a list
-------------------------------------+-------------------------------------
Reporter: Zerq | Owner: Tanish
| Yelgoe
Type: Bug | Status: closed
Component: contrib.postgres | Version:
Severity: Normal | Resolution: wontfix
Keywords: ArrayField | Triage Stage:
to_python | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):
* resolution: => wontfix
* status: new => closed
Comment:
Looking at the linked docs: (
https://docs.djangoproject.com/en/5.1/howto
/custom-model-fields/#converting-values-to-python-objects
>to_python() is called by deserialization and during the clean() method
used from forms.
>As a general rule, to_python() should deal gracefully with any of the
following arguments:
>
>* An instance of the correct type (e.g., Hand in our ongoing example).
>
>* A string
Does it handle an instance of the correct type?
Yes, `[1, 2, 3]` would be correct in terms of a ArrayField with an
IntegerField base_field, and `[1, "2", 3]` is not a valid array field with
integer base
Does it handle a deserialization (the string case) correctly?
Yes, when we serialize an ArrayField with `[1, 2, 3]` we get `'["1", "2",
"3"]'` which is handled to be valid.
To me, the odd case is that `'[1, "2", 3]'` valid. That's because we get
`'[1, "2", 3]'` apply `json.load` and get `[1, "2", 3]` and then the
`to_python` of the base fields handle both strings (as the deserializer
case) but also the case that it just received a value of the correct
instance. We _possibly_ could handle this. I am not sure the cost benefit.
So I am adjusting this to "wontfix". This means you can start a new
conversation on the [
https://forum.djangoproject.com/c/internals/5 Django
Forum], where you'll reach a broader audience and receive additional
feedback, if there is consensus that we should change this. You can reopen
the ticket.
--
Ticket URL: <
https://code.djangoproject.com/ticket/35946#comment:5>
Django <
https://code.djangoproject.com/>
The web framework for perfectionists with deadlines.