Opened 7 years ago

Closed 7 years ago

#28049 closed Bug (duplicate)

ArrayField of IntegerField-s with Choices does not pass validation

Reported by: Denis Sumin Owned by: nobody
Component: contrib.postgres Version: 1.11
Severity: Normal Keywords: arrayfield
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have an ArrayField with IntegerField inside, and the IntegerField has choices.
Widgets return back a list of strings (instead of a list of integers). That is why the validation fails.
I've found that changing ArrayField.to_python from this

    def to_python(self, value):
        if isinstance(value, six.string_types):
            # Assume we're deserializing
            vals = json.loads(value)
            value = [self.base_field.to_python(val) for val in vals]
        return value

to something like this

    def to_python(self, value):
        if isinstance(value, six.string_types):
            # Assume we're deserializing
            vals = json.loads(value)
            value = [self.base_field.to_python(val) for val in vals]
        elif isinstance(value, list):
            value = [self.base_field.to_python(val) for val in value]
        return value

fixes the problem.

Change History (2)

comment:1 by Denis Sumin, 7 years ago

Component: Uncategorizedcontrib.postgres
Type: UncategorizedBug

comment:2 by Marc Tamlyn, 7 years ago

Resolution: duplicate
Status: newclosed

This appears to be a duplicate of #27161

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