Opened 17 years ago
Closed 17 years ago
#6211 closed (invalid)
newforms.models.save_instance boolean field TypeError
Reported by: | Seth Buntin | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When a boolean field (checkbox) isn't sent (because it isn't checked) i get a failure "Type Error: argument of type 'bool' is not iterable"
Attachments (2)
Change History (8)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
Sorry for the lack of information. Here is a bit more detailed information, I was busy at the time of creating this ticket. The problem seemed to be with code lines 42 and 43, because all worked when I commented them out.
if fields and f.name not in fields:
continue
After uncommenting those line and testing again, all seems well. This is weird. Sorry for the waste of time.
comment:3 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Closing, based on previous comment.
comment:4 by , 17 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
After deploying site I am getting this error again. I am going to do my best to document my issues. Here is the traceback:
Environment:
Request Method: POST
Request URL: http://market_stand.cabedgedev.com/admin/products/categories/new/
Django Version: 0.97-pre-SVN-6941
Python Version: 2.5.1
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'market_stand.products',
'market_stand.orders',
'market_stand.shipping',
'market_stand.customers',
'market_stand.shop']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware')
Traceback:
File "/apps/shared/django/6941/django/core/handlers/base.py" in get_response
- response = callback(request, *callback_args, callback_kwargs)
File "/apps/market_stand/current/market_stand/products/categories/views.py" in new
- category = form.save()
File "/apps/market_stand/current/market_stand/products/categories/forms.py" in save
- return forms.models.save_instance(self, instance, commit)
File "/apps/shared/django/6941/django/newforms/models.py" in save_instance
- if fields and f.name not in fields:
Exception Type: TypeError at /admin/products/categories/new/
Exception Value: argument of type 'bool' is not iterable
Here is the form I am using to save the instance:
class CategoryForm(forms.Form):
"""(CategoryForm description)"""
name = forms.CharField(max_length=100)
parent = forms.ModelChoiceField(queryset=Category.objects.all(), required=False)
def clean_parent(self):
try:
category = Category.objects.get(nameexact=self.cleaned_dataparent)
except Category.DoesNotExist:
return self.cleaned_dataparent
if category.has_parent():
raise forms.ValidationError('Categories are only meant to be nested two deep. Your parent category can\'t have children.')
return self.cleaned_dataparent
def save(self, id=None, commit=True):
if not id:
instance = Category()
else:
instance = Category.objects.get(pk=id)
return forms.models.save_instance(self, instance, commit)
by , 17 years ago
Attachment: | save_instance.2.diff added |
---|
Patch to fix TypeError? issue. Checks for fields before acting upon it.
comment:5 by , 17 years ago
This also doesn't have anything to do with a checkbox like I said in the initial comment. This has everything to do with not sending anything via the fields kwarg to the method.
comment:6 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
In your code:
return forms.models.save_instance(self, instance, commit)
should be:
return forms.models.save_instance(self, instance, commit=commit)
You can't pass commit in as simply a positional parameter without also passing in fields and fail_message ahead of it. If you want to pass just commit, you have to pass it as a keyword argument. With the call you are making, whatever value commit has is what save_instance is using for fields, which is why you see the error about a bool not being iterable.
This bug report is lacking a lot of information. How do we reproduce this problem? What are the circumstances under which the problem occurs?