Opened 21 months ago

Last modified 13 months 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

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

comment:1 Changed 21 months ago by Scott Allen

Owner: set to Scott Allen
Status: newassigned

comment:2 Changed 21 months ago by Scott Allen

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 Changed 21 months ago by Simon Charette

Triage Stage: UnreviewedAccepted

comment:4 Changed 21 months 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 18 months ago by Michael

Cc: michaelvantellingen@… added

comment:6 Changed 13 months 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 https://code.djangoproject.com/ticket/21397 (which I don't think I agree with)

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