#21568 closed Bug (fixed)
ModelMultipleChoiceField + show_hidden_initial + has_changed = TypeError
Reported by: | Owned by: | Claude Paroz | |
---|---|---|---|
Component: | Forms | Version: | 1.6 |
Severity: | Release blocker | Keywords: | ModelMultipleChoiceField show_hidden_initial |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
hi
def test(request): u""" for debug and test's """ from django import forms from django.http import HttpResponse from django.template import RequestContext, Template user = models.User.objects.get(pk=1) changed = None class TestForm(forms.Form): users = forms.ModelMultipleChoiceField(show_hidden_initial=True, queryset=models.User.objects.all()) if request.method == 'POST': form = TestForm(data=request.POST) form.is_valid() ### next line raised: TypeError int() argument must be a string or a number, not 'list' ### ### django/db/models/fields/__init__.py in get_prep_value, line 613 ### changed = form.has_changed() else: form = TestForm(initial={'users': [user]}) c = RequestContext(request, {'form': form, 'changed': changed}) t = Template(""" <form method=POST> {% csrf_token %} {{form}} <input type=submit> </form> {{changed}} """) return HttpResponse(t.render(c))
if change to:
users = forms.ModelMultipleChoiceField(queryset=models.User.objects.all())
and
form = TestForm(data=request.POST, initial={'users': [user]})
This works, but may lead to loss of the changes made by other users
Change History (8)
comment:1 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
follow-up: 4 comment:2 by , 11 years ago
Can you provide a full traceback please? If you're seeing Django's error debug page, there's a button to show a copy-pasteable backtrace. Please add it in a comment.
comment:3 by , 11 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
The base issue is that ModelMultipleChoiceField
has currently no to_python
method. Previously (1.5), has_changed
did not call to_python
on values coming from hidden initial widgets, so this issue remained unnoticed. Hence, this is also a regression.
comment:4 by , 11 years ago
Replying to aaugustin:
Can you provide a full traceback please? If you're seeing Django's error debug page, there's a button to show a copy-pasteable backtrace. Please add it in a comment.
traceback still needed?
comment:5 by , 11 years ago
Has patch: | set |
---|
Generally, traceback is appreciated, yes. But now that we have a patch to fix the issue, it's not useful any more. Please check if the following patch solves your issue.
comment:7 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
I'll investigate...