[Django] #21397: forms.TypedChoiceField validation problem

30 views
Skip to first unread message

Django

unread,
Nov 7, 2013, 5:25:33 AM11/7/13
to django-...@googlegroups.com
#21397: forms.TypedChoiceField validation problem
-------------------------------+--------------------
Reporter: Elec | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
I get ValidationError on this code:

{{{
POST_DAYS_CHOICE = (
(7, '1 week'),
(14, '2 weeks'),
(30, '1 month'),
(60, '2 months'),
(90, '3 months'),
)

def days_to_till_date(val):
print val
try:
till_date = date.today() + timedelta(int(val))
except ValueError:
till_date = date.today() + timedelta(30)
return till_date

class PostForm(forms.ModelForm):
till_date = forms.TypedChoiceField(label='Period',
choices=POST_DAYS_CHOICE, coerce=days_to_till_date, required=True,
initial=30)

}}}

This is was removed from TypedChoiceField class:

{{{
def validate(self, value):
pass
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21397>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 7, 2013, 8:17:48 AM11/7/13
to django-...@googlegroups.com
#21397: forms.TypedChoiceField validation problem
---------------------------------+------------------------------------
Reporter: Elec | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.6
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by claudep):

* severity: Normal => Release blocker
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

This was changed in [9883551d50e].

Interesting use case, which is currently not tested in Django. Having the
coerced value not in choices is a bit of a corner case (and not clearly
documented), but I admit this might be considered as a regression.

I'll see if I can come up with a fix which is not too invasive...

In any case, the documentation will have to be clarified on this point.

--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:1>

Django

unread,
Nov 7, 2013, 8:59:32 AM11/7/13
to django-...@googlegroups.com
#21397: forms.TypedChoiceField validation problem
---------------------------------+------------------------------------
Reporter: Elec | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.6

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by claudep):

* has_patch: 0 => 1


Comment:

Attached a patch with a possible fix. Test suite passes with SQLite. I'll
let other core developers judge if this warrants to be added in a stable
release.

--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:2>

Django

unread,
Nov 7, 2013, 3:19:11 PM11/7/13
to django-...@googlegroups.com
#21397: forms.TypedChoiceField validation problem
---------------------------------+------------------------------------
Reporter: Elec | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.6

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by claudep):

Thinking a bit more about this, I think that it's too risky to push my
patch in the 1.6 stable branch. We can document the regression in the 1.6
release notes, but you will probably have to create a custom field to
workaround the issue until the next release.
Please, next time try to test your project with beta or at least RC
releases, so we can catch those issues before the official release.

--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:3>

Django

unread,
Nov 8, 2013, 7:41:33 AM11/8/13
to django-...@googlegroups.com
#21397: forms.TypedChoiceField validation problem
---------------------------------+------------------------------------
Reporter: Elec | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.6

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by Elec):

Hi, no problem. I just test my project with 1.6 release. I create custom
field.

--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:4>

Django

unread,
Nov 17, 2013, 3:24:27 PM11/17/13
to django-...@googlegroups.com
#21397: forms.TypedChoiceField validation problem
---------------------------------+------------------------------------
Reporter: Elec | Owner: claudep
Type: Bug | Status: assigned
Component: Forms | Version: 1.6

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by claudep):

* owner: nobody => claudep
* status: new => assigned


Comment:

Assigned to me, but would love to receive another core dev opinion.

--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:5>

Django

unread,
Nov 17, 2013, 5:30:56 PM11/17/13
to django-...@googlegroups.com
#21397: forms.TypedChoiceField validation problem
------------------------+---------------------------------------------

Reporter: Elec | Owner: claudep
Type: Bug | Status: assigned
Component: Forms | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------+---------------------------------------------
Changes (by charettes):

* severity: Release blocker => Normal
* stage: Accepted => Ready for checkin


Comment:

While you did a great job at putting a non-invasive patch together I'm not
sure we should commit to backport it.

First because it doesn't meet any of the policy criterias and second
because it concerns an undocumented and corner use case.

IMHO the small risk of introducing another regression, there's a small one
given the original `to_python` override, is not worth the backport.

On the other hand -- apart the missing a release note -- the patch looks
RFC for master.

--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:6>

Django

unread,
Nov 18, 2013, 7:28:06 AM11/18/13
to django-...@googlegroups.com
#21397: forms.TypedChoiceField validation problem
------------------------+---------------------------------------------
Reporter: Elec | Owner: claudep
Type: Bug | Status: assigned
Component: Forms | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------+---------------------------------------------

Comment (by claudep):

Proposal for a 1.6 release note addition (misc backwards
incompatibilities):
{{{
* Due to a change in the form validation workflow,
:class:`~django.forms.TypedChoiceField` ``coerce`` method should always
return a value present in the ``choices`` field attribute. That
limitation
should be lift again in Django 1.7.
}}}
Does it look sane?

--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:7>

Django

unread,
Nov 18, 2013, 11:18:27 AM11/18/13
to django-...@googlegroups.com
#21397: forms.TypedChoiceField validation problem
------------------------+---------------------------------------------
Reporter: Elec | Owner: claudep
Type: Bug | Status: assigned
Component: Forms | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------+---------------------------------------------

Comment (by charettes):

LGTM

--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:8>

Django

unread,
Nov 18, 2013, 12:09:33 PM11/18/13
to django-...@googlegroups.com
#21397: forms.TypedChoiceField validation problem
------------------------+---------------------------------------------
Reporter: Elec | Owner: claudep
Type: Bug | Status: assigned
Component: Forms | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------+---------------------------------------------

Comment (by Claude Paroz <claude@…>):

In [changeset:"4a00f132e0cc5246f7e7bd04b6d84a9d9ea4a0c1"]:
{{{
#!CommitTicketReference repository=""
revision="4a00f132e0cc5246f7e7bd04b6d84a9d9ea4a0c1"
Added release note for TypedChoiceField coerce limitation

Thanks Elec for the report and Simon Charette for the review.
Refs #21397.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:9>

Django

unread,
Nov 18, 2013, 12:10:35 PM11/18/13
to django-...@googlegroups.com
#21397: forms.TypedChoiceField validation problem
------------------------+---------------------------------------------
Reporter: Elec | Owner: claudep
Type: Bug | Status: assigned
Component: Forms | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------+---------------------------------------------

Comment (by Claude Paroz <claude@…>):

In [changeset:"9f59149cfe97b3b0026bbc4ff1d2121e4cf04d0e"]:
{{{
#!CommitTicketReference repository=""
revision="9f59149cfe97b3b0026bbc4ff1d2121e4cf04d0e"
[1.6.x] Added release note for TypedChoiceField coerce limitation

Thanks Elec for the report and Simon Charette for the review.
Refs #21397.

Backport of 4a00f132e0 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:10>

Django

unread,
Nov 18, 2013, 12:30:55 PM11/18/13
to django-...@googlegroups.com
#21397: forms.TypedChoiceField validation problem
------------------------+---------------------------------------------
Reporter: Elec | Owner: claudep
Type: Bug | Status: closed
Component: Forms | Version: 1.6
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------+---------------------------------------------
Changes (by Claude Paroz <claude@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"a0f3eeccf3d5a90f9914bfe20b15df05673ea59d"]:
{{{
#!CommitTicketReference repository=""
revision="a0f3eeccf3d5a90f9914bfe20b15df05673ea59d"
Fixed #21397 -- Re-added flexibility to TypedChoiceField coercion

Thanks Elec for the report and Simon Charette for the review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:11>

Reply all
Reply to author
Forward
0 new messages