Opened 8 years ago
Closed 8 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 , 8 years ago
Component: | Uncategorized → contrib.postgres |
---|---|
Type: | Uncategorized → Bug |
comment:2 by , 8 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
This appears to be a duplicate of #27161