Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

form instance is incorrectly propagated to other forms #1

Closed
marcinn opened this issue Dec 12, 2011 · 3 comments
Closed

form instance is incorrectly propagated to other forms #1

marcinn opened this issue Dec 12, 2011 · 3 comments

Comments

@marcinn
Copy link

marcinn commented Dec 12, 2011

if instance is None a previous kwargs dictionary is used in next iteration.
Affected code (forms.CompositeForm.__init__):

        for form in self.form_list:
            if self.get_form_instance(form):
                kwargs.update({"instance": self.get_form_instance(form)})
            self._form_instances[form] = form(data, files, *args, **kwargs)

a possible fix:

        for form in self.form_list:
            kwargs = initkwargs.copy()
            if self.get_form_instance(form):
                kwargs.update({"instance": self.get_form_instance(form)})
            self._form_instances[form] = form(data, files, *args, **kwargs)
marcinn pushed a commit to marcinn/django-composite-form that referenced this issue Dec 12, 2011
@t0ster
Copy link
Owner

t0ster commented Dec 12, 2011

Can you provide sample code of how to reproduce bug.

Thanks!

@marcinn
Copy link
Author

marcinn commented Dec 19, 2011

Some like this:

class MyForm(CompositeForm):
  form_list = UserModelForm, ModelForm1, ModelForm2

def object_create(request):
  form = MyForm(data=request.POST, instances=[request.user, None, None])

in first iteration you have an User instance that is reused for ModelForm1 and ModelForm2

t0ster added a commit that referenced this issue Dec 20, 2011
@t0ster
Copy link
Owner

t0ster commented Dec 20, 2011

Thanks!

@t0ster t0ster closed this as completed Dec 20, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants