Opened 3 years ago

Last modified 3 years ago

#26251 assigned Bug

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: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


For reproduction and screenshot of admin error see:

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 (6)

comment:1 Changed 3 years ago by Scott Allen

Owner: set to Scott Allen
Status: newassigned

comment:2 Changed 3 years ago by Scott Allen

I've created a pull request:

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 Changed 3 years ago by Simon Charette

Triage Stage: UnreviewedAccepted

comment:4 Changed 3 years ago by Tim Graham

Patch needs improvement: set

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

comment:5 Changed 3 years ago by Michael

Cc: michaelvantellingen@… added

comment:6 Changed 3 years ago by David Szotten

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 (which I don't think I agree with)

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