Opened 13 years ago
Closed 13 years ago
#17759 closed Bug (duplicate)
FormMixin instantiates form with dict stored on the class
Reported by: | Aron Grififs | Owned by: | nobody |
---|---|---|---|
Component: | Generic views | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | aron@…, charette.s@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Consider the following form:
class MyForm(ModelForm): def __init__(self, *args, **kwargs): kwargs['initial']['foo'] = 'bar' super(MyForm, self).__init__(*args, **kwargs)
When used with Django's class-based generic views, this will cause all following form instantiations to have a default initial
dict with the content {'foo': 'bar'}
because the dict is inadvertently updated on the class.
The problem is the following code in [source:django/trunk/django/views/generic/edit.py generic/edit.py]:
class FormMixin(object): initial = {} def get_initial(self): return self.initial def get_form_kwargs(self): kwargs = {'initial': self.get_initial()} ...
I think the right fix here is to shallow-copy the dict in get_initial, will attach patch.
Attachments (2)
Change History (9)
by , 13 years ago
Attachment: | django-17759.patch added |
---|
comment:1 by , 13 years ago
Cc: | added |
---|---|
Has patch: | set |
comment:2 by , 13 years ago
Type: | Uncategorized → Bug |
---|
comment:3 by , 13 years ago
Needs tests: | set |
---|
comment:4 by , 13 years ago
Cc: | added |
---|
by , 13 years ago
Attachment: | 17759-2.diff added |
---|
comment:5 by , 13 years ago
Needs tests: | unset |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:6 by , 13 years ago
Will this ticket be closed before the release of 1.4? We currently have a monkeypatch in place to deal with the problem, but I'd like to remove it when 1.4 is official.
comment:7 by , 13 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
This is in fact a duplicate of #16138. Thanks aaugustin for the notice.
With test