Opened 9 years ago

Closed 5 years ago

#26251 closed Bug (duplicate)

SimpleArrayField missing clean method which leads to unexpected validation error.

Reported by: Scott Allen Owned by: Scott Allen
Component: contrib.postgres Version: 1.9
Severity: Normal Keywords: postgres, arrayfield, simplearrayfield
Cc: michaelvantellingen@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

For reproduction and screenshot of admin error see: https://github.com/sgallen/django-simplearrayfield-bug

When a model field of the following form is used:
ArrayField(models.IntegerField(choices=((0, 'foo'),(1, 'bar'))))

The submission of a seemingly valid value e.g. 1 via the admin form leads to the unexpected message:
Item 0 in the array did not validate:

There is no additional message after the colon.

The cause of this error is a missing clean method in the SimpleArrayField. As a result, there is no call to self.base_field.clean(item) which in this case is the TypedChoiceField. Consequently the submitted string value is never coerced to an int and therefore the string comparison to the int choices will always fail.

Change History (7)

comment:1 by Scott Allen, 9 years ago

Owner: set to Scott Allen
Status: newassigned

comment:2 by Scott Allen, 9 years ago

I've created a pull request: https://github.com/django/django/pull/6174

If I'm missing anything or my adherence to the standard contribution protocol is off, please let me know. This is my first time doing this.

comment:3 by Simon Charette, 9 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Tim Graham, 9 years ago

Patch needs improvement: set

I'm not yet convinced that so much duplication between to_python() and clean() is the proper solution.

comment:5 by Michael, 8 years ago

Cc: michaelvantellingen@… added

comment:6 by David Szotten, 8 years ago

i'm wondering if the issue is with the TypedChoiceField. I was thinking it should do the coercion in a to_python method and not in clean. The problem with that is https://code.djangoproject.com/ticket/21397 (which I don't think I agree with)

comment:7 by Mariusz Felisiak, 5 years ago

Has patch: unset
Patch needs improvement: unset
Resolution: duplicate
Status: assignedclosed
Note: See TracTickets for help on using tickets.
Back to Top