#27161: TypedChoiceField validation bug
----------------------------+------------------------------
     Reporter:  th13f       |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Forms       |    Version:  master
     Severity:  Normal      |   Keywords:  TypedChoiceField
 Triage Stage:  Unreviewed  |  Has patch:  1
Easy pickings:  0           |      UI/UX:  0
----------------------------+------------------------------
 Example model:

 {{{
 from django.contrib.postgres.fields import ArrayField

 class ArrayFieldTestModel(models.Model):
     CHOICES = map(lambda x: (x, str(x)), range(10))

     test_field = ArrayField(models.IntegerField(choices=CHOICES),
 blank=True, null=True)

 }}}


 On form saving we'll got validation error for valid choices:
 [[Image(https://snag.gy/DGNVtR.jpg)]]

 This is caused by validation ordering:
 1. TypedChoiceField clean method called
 2. Field clean method called (super)
 3. to_python method called, which should transform value to correct, but
 it doesn't.
 3. TypedChoiceField validate called, which raise ValidationError: no such
 choice. He is trying to find string value in integers array and can't do
 this.
 4. after super clean method, TypedChoiceField is trying to coerce value
 (it's too late, error was raised before this).

 this can be easily fixed by moving _coerce call into `to_python`.

--
Ticket URL: <https://code.djangoproject.com/ticket/27161>
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/048.4b55f47d806a62b5ed16afa64540168d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to