Code

Opened 7 years ago

Closed 7 years ago

#3635 closed (fixed)

KeyError in newforms.models.save_instance()

Reported by: ludo@… Owned by: adrian
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

A KeyError is raised by when saving a custom form (created with form_for_model(inst, form=CustomForm) if it has less fields than the model it refers to. As custom forms are a handy way to expose only a subset of the available fields, checking for the field in the form's clean_data before setting its value in the model seems a good idea.

Attachments (1)

models.diff (1.0 KB) - added by ludo@… 7 years ago.

Download all attachments as: .zip

Change History (5)

Changed 7 years ago by ludo@…

comment:1 Changed 7 years ago by ludo@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Ugh, not form_for_model(inst, form=CustomForm) but form_for_instance(inst, form=CustomForm). Newforms are melting my brain...

comment:2 Changed 7 years ago by ludo@…

  • Summary changed from KeyError in newforms.models.save_instance() [patch] to [patch] KeyError in newforms.models.save_instance()

comment:3 Changed 7 years ago by Simon G. <dev@…>

  • Has patch set
  • Summary changed from [patch] KeyError in newforms.models.save_instance() to KeyError in newforms.models.save_instance()
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:4 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(In [4878]) Fixed #3635 -- Fixed KeyError problem in newforms.model.save_instance().
Thanks, ludo@….

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.