[Django] #22678: forms.Form silently won't bind to POST data (under certain combinations of key and label)

8 views
Skip to first unread message

Django

unread,
May 22, 2014, 5:24:00 AM5/22/14
to django-...@googlegroups.com
#22678: forms.Form silently won't bind to POST data (under certain combinations of
key and label)
------------------------------+--------------------
Reporter: brycenesbitt | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.5
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+--------------------
In this example:


{{{
class TestFormX(forms.Form):
test_one = forms.CharField(required=True)

def __init__(self, *args, **kwargs):
super(TestFormX, self).__init__(*args, **kwargs)

self.fields['test_two'] = forms.IntegerField(required=False)
for key in (3,4):
self.fields[key] = forms.IntegerField(required=False,
label='must have a label')

def sandbox2(request):
if request.method == 'POST':
form = TestFormX(request.POST)
if form.is_valid():
print 'Form is valid'
else:
print form.errors
else:
form = TestFormX()
return render(request, 'xxx_sandbox2.html', {'form' : form},
status=200)

}}}

Form fields test_one and test_two act normally. Fields 3 and 4 render and
appear to work, but
won't bind data from the request.POST. Thus, any input by the user is
lost.

This was found on a dynamically built from.Form, where an integer database
primary key was used as the field name.

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

Django

unread,
May 22, 2014, 7:25:38 AM5/22/14
to django-...@googlegroups.com
#22678: forms.Form silently won't bind to POST data (under certain combinations of
key and label)
------------------------------+--------------------------------------
Reporter: brycenesbitt | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 1.5
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* status: new => closed
* needs_better_patch: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_docs: => 0


Comment:

Hi,

I believe the problem here is that you're using integers as keys on
`TestFormX.fields` which is not supported (only strings are allowed).

Things should work if you use `for key in ('3', '4'):`.

Marking this as `invalid` consequently.

Thanks.

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

Django

unread,
May 22, 2014, 2:13:44 PM5/22/14
to django-...@googlegroups.com
#22678: forms.Form silently won't bind to POST data (under certain combinations of
key and label)
------------------------------+--------------------------------------

Reporter: brycenesbitt | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

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

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

* status: closed => new
* resolution: invalid =>


Comment:

I intended to convey that above: the issue is the integer. Strings work,
integers don't.
The form as build 'looked' like reasonable code, but had a murky and hard
to track problem.
Most code paths blow up on integers, but not this one.


The proposed fix is to assert on string for the key.

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

Django

unread,
May 28, 2014, 7:43:45 PM5/28/14
to django-...@googlegroups.com
#22678: forms.Form silently won't bind to POST data (under certain combinations of
key and label)
------------------------------+--------------------------------------
Reporter: brycenesbitt | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 1.5
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed

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

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

* status: new => closed

* resolution: => wontfix


Comment:

I think it's reasonable to expect that most people won't mix types in the
`fields` dictionary. I'm sorry you ran into the issue, but I don't think
fixing it is worthwhile.

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

Reply all
Reply to author
Forward
0 new messages