Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #3635 -- Fixed KeyError problem in newforms.model.save_instance().

Thanks, ludo@qix.it.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@4878 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6a5deb6bc0ca6260b2af374583737c3c63a3037b 1 parent 1ccdcbf
Malcolm Tredinnick malcolmt authored
Showing with 3 additions and 2 deletions.
  1. +3 −2 django/newforms/models.py
5 django/newforms/models.py
View
@@ -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 f.name in clean_data:
continue
setattr(instance, f.name, clean_data[f.name])
if commit:
instance.save()
for f in opts.many_to_many:
- setattr(instance, f.attname, clean_data[f.name])
+ if f.name in clean_data:
+ setattr(instance, f.attname, clean_data[f.name])
# 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
Please sign in to comment.
Something went wrong with that request. Please try again.