Browse files

Fixed #3635 -- Fixed KeyError problem in newforms.model.save_instanc…



git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
malcolmt committed Mar 31, 2007
1 parent 1ccdcbf commit 6a5deb6bc0ca6260b2af374583737c3c63a3037b
Showing with 3 additions and 2 deletions.
  1. +3 −2 django/newforms/
@@ -36,13 +36,14 @@ def save_instance(form, instance, commit=True):
raise ValueError("The %s could not be changed because the data didn't validate." % opts.object_name)
clean_data = form.clean_data
for f in opts.fields:
- if not f.editable or isinstance(f, models.AutoField):
+ if not f.editable or isinstance(f, models.AutoField) or not in clean_data:
setattr(instance,, clean_data[])
if commit:
for f in opts.many_to_many:
- setattr(instance, f.attname, clean_data[])
+ if in clean_data:
+ setattr(instance, f.attname, clean_data[])
# GOTCHA: If many-to-many data is given and commit=False, the many-to-many
# data will be lost. This happens because a many-to-many options cannot be
# set on an object until after it's saved. Maybe we should raise an

0 comments on commit 6a5deb6

Please sign in to comment.