Opened 5 hours ago

#35946 new Bug

Postgres ArrayField should convert values when given a list

Reported by: Zerq Owned by:
Component: contrib.postgres Version:
Severity: Normal Keywords: ArrayField to_python
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Currently ArrayField.to_python only calls base_field.to_python when given string. In my opinion it should call it always. Currently using this field is inconsistent. Simple example:

    f = MyModel._meta.get_field("int_array")
    f.clean('[1, "2", 3]', None) # ok
    f.clean([1, "2", 3], None) # error

Proposed ArrayField.to_python, witch always calls base_field.to_python(val):

    def to_python(self, value):
        if isinstance(value, str):
            value = json.loads(value)
        return [self.base_field.to_python(val) for val in value]

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top