#17759: FormMixin instantiates form with dict stored on the class
-------------------------------+--------------------
     Reporter:  agriffis       |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Generic views  |    Version:  1.3
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 Consider the following form:

 {{{
 #!python
 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]:

 {{{
 #!python
 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/17759>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to