Opened 9 years ago

Closed 9 years ago

#6211 closed (invalid)

newforms.models.save_instance boolean field TypeError

Reported by: Seth Buntin Owned by: nobody
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


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)

save_instance.2.diff (1.1 KB) - added by Seth Buntin 9 years ago.
Patch to fix TypeError? issue. Checks for fields before acting upon it.
save_instance.diff (1.0 KB) - added by Seth Buntin 9 years ago.
fix patch index

Download all attachments as: .zip

Change History (8)

comment:1 Changed 9 years ago by Malcolm Tredinnick

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

This bug report is lacking a lot of information. How do we reproduce this problem? What are the circumstances under which the problem occurs?

comment:2 Changed 9 years ago by Seth Buntin

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 not in fields:


After uncommenting those line and testing again, all seems well. This is weird. Sorry for the waste of time.

comment:3 Changed 9 years ago by Malcolm Tredinnick

Resolution: invalid
Status: newclosed

Closing, based on previous comment.

comment:4 Changed 9 years ago by Seth Buntin

Resolution: invalid
Status: closedreopened

After deploying site I am getting this error again. I am going to do my best to document my issues. Here is the traceback:


Request Method: POST
Request URL:
Django Version: 0.97-pre-SVN-6941
Python Version: 2.5.1
Installed Applications:


Installed Middleware:


File "/apps/shared/django/6941/django/core/handlers/" in get_response

  1. response = callback(request, *callback_args, callback_kwargs)

File "/apps/market_stand/current/market_stand/products/categories/" in new

  1. category =

File "/apps/market_stand/current/market_stand/products/categories/" in save

  1. return forms.models.save_instance(self, instance, commit)

File "/apps/shared/django/6941/django/newforms/" in save_instance

  1. if fields and 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):


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()


instance = Category.objects.get(pk=id)

return forms.models.save_instance(self, instance, commit)

Changed 9 years ago by Seth Buntin

Attachment: save_instance.2.diff added

Patch to fix TypeError? issue. Checks for fields before acting upon it.

Changed 9 years ago by Seth Buntin

Attachment: save_instance.diff added

fix patch index

comment:5 Changed 9 years ago by Seth Buntin

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 Changed 9 years ago by Karen Tracey <kmtracey@…>

Resolution: invalid
Status: reopenedclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top