#28049: ArrayField of IntegerField-s with Choices does not pass validation
-----------------------------------------+----------------------------
Reporter: denis-sumin | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Keywords: arrayfield
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+----------------------------
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/28049>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/054.154eacbee925c12b7e69ac933a14aab9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.