self.extra_context is a reference of FormWizard.extra_context.
It was empty when the class define, but may not empty when
instantiate.

class TestWizard(forms.FormWizard):
    pass

tw1 = TestWizard()
tw1(request, extra_context={'test1': 1})
# tw1.extra_context is {'test1': 1}

tw2 = TestWizard()
tw2(request, extra_context={'test2': 2})
# tw1.extra_context and tw2.extra_context both are {'test1': 1,
'test2':2}

My fix will let self.extra_context to be a copy of
FormWizard.extra_context,
so change to self.extra_context will not affect
FormWizard.extra_context.

On Dec 18, 11:02 pm, Rajesh Dhawan <[email protected]> wrote:
> wrote:
> > On Dec 17, 7:49 am, Rajesh Dhawan <[email protected]> wrote:
> > > On Dec 16, 2:31 am, $B<kKTKT (B <[email protected]> wrote:
>
> > > > Theextra_contextinFormWizardis a class attribute so the new
> > > > request may get the context of the previous request.
> > > > I can prepend below to __call__ method to solved it:
>
> > > > self.extra_context= self.extra_context.copy()
>
> > > > Is this really a bug?
>
> > > It's most probably a bug. See:http://code.djangoproject.com/ticket/8808
>
> > > Basically, if you hook theFormWizardinto your URL config as
> > > documented 
> > > athttp://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizar...,
> > > anything you set in self.extra_contextmay become available to another
> > > request.
>
> > > Your fix to copy theextra_contextdoesn't solve this problem.
>
> > > Quoting an excerpt from Jacob's response on that ticket: "I should
> > > note that the workaround is very simple: either don't store state on
> > > self, or instantiate the wizard in a view function. "
>
> > > -Rajesh D
>
> > I already instantiate the wizard in a view function when I send the
> > first mail.
> > Please notice that the extra_context is a class attribute.
>
> While it can be used as a class attribute, the FormWizard API asks you
> to use it as an instance attribute (i.e. self.extra_context instead of
> FormWizard.extra_context).
>
> > Just instantiate the wizard in a view function did not solved the
> > problem, and my fix will solve it.
>
> > Add below will fix when instantiate the wizard in urlconf:
>
> > Change the last line in __call__ from:
> >   return self.render(form, request, current_step)
> > to:
> >   response = self.render(form, request, current_step)
> >   del self.extra_context  # here the extra_context is a copy in
> > instance, once delete, the next request will copy one from the class
> > extra_context
> >   return response
>
> That's not needed if you instantiate FormWizard every time the view is
> called because each new instance of FormWizard will give you an empty
> self.extra_context to begin with.
>
> Can you show your view and url conf code fragments that did not work?
>
> -Rajesh
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to