FormMixin instantiates form with dict stored on the class
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.
Change History
(9)
| Cc: |
aron@… added
|
| Has patch: |
set
|
| Type: |
Uncategorized → Bug
|
| Needs tests: |
unset
|
| Triage Stage: |
Unreviewed → Accepted
|
| Resolution: |
→ duplicate
|
| Status: |
new → closed
|
With test