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 , 9 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:2 by , 9 years ago
comment:3 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 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 , 9 years ago
Cc: | added |
---|
comment:6 by , 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 , 5 years ago
Has patch: | unset |
---|---|
Patch needs improvement: | unset |
Resolution: | → duplicate |
Status: | assigned → closed |
Duplicate of #27161, fixed in 9dd244394236388c3479ab202a0ec31055f7ec09.
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.