Opened 7 years ago

Closed 7 years ago

Last modified 5 years ago

#11872 closed (fixed)

can't pass instance=None to inline formset

Reported by: tobias Owned by: brosner
Component: Forms Version: 1.1
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


If you try to pass instance=None to a new unbound formset you get an exception:

Traceback (most recent call last):
  File "/home/tobias/caktus/eclipse-workspace/django-trunk/tests/regressiontests/model_formsets_regress/", line 152, in test_formset_with_none_instance
    form_set = FormSet(instance=None)
  File "../django/forms/", line 721, in __init__
    backlink_value = getattr(self.instance,
AttributeError: 'UserSite' object has no attribute 'username'

because the formset is trying to instantiate the wrong type of model in place of the None instance.

A quick one-line change fixes the problem. Attached is a patch with a test demonstrating the problem and the proposed solution.

Attachments (1)

inline_formsets_none_instance.diff (1.4 KB) - added by tobias 7 years ago.
add ticket # to test in patch

Download all attachments as: .zip

Change History (4)

Changed 7 years ago by tobias

add ticket # to test in patch

comment:1 Changed 7 years ago by brosner

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to brosner
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 7 years ago by brosner

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

(In [11688]) Fixed #11872 -- Instantiate the correct model in BaseInlineFormSet.init when instance is None. Thanks tobias.

comment:3 Changed 5 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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