#11872 closed (fixed)
can't pass instance=None to inline formset
Reported by: | Tobias McNulty | Owned by: | Brian Rosner |
---|---|---|---|
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: | no | UI/UX: | no |
Description
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/tests.py", line 152, in test_formset_with_none_instance form_set = FormSet(instance=None) File "../django/forms/models.py", line 721, in __init__ backlink_value = getattr(self.instance, self.fk.rel.field_name) 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)
Change History (4)
by , 15 years ago
Attachment: | inline_formsets_none_instance.diff added |
---|
comment:1 by , 15 years ago
Owner: | changed from | to
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
add ticket # to test in patch