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

query params attribute is shared between form instances. #216

Open
sjoerdjob opened this issue Jun 30, 2020 · 0 comments
Open

query params attribute is shared between form instances. #216

sjoerdjob opened this issue Jun 30, 2020 · 0 comments

Comments

@sjoerdjob
Copy link

When one has an instance of the form, and calls

    self.fields["fieldname"].widget.update_query_parameters({"foo": "bar"})

it turns out that the update also happens for all other instances of the form.

Example: I added the following to selectable/tests/test_functional.py

    def test_update_query_parameters_isolation(self):
        form = SimpleForm()
        form.fields["thing"].widget.update_query_parameters({"foo": "bar"})
        self.assertIn("foo=bar", form.as_ul())

        form = SimpleForm()  # Construct a new instance
        self.assertNotIn("foo=bar", form.as_ul())

and this test failed: the new form instance still had foo=bar in the URL.

Fix seems to be adding the following to AutoCompleteWidget

    def __deepcopy__(self, memo):
        obj = super().__deepcopy__(memo)
        obj.qs = deepcopy(self.qs, memo)
        return obj
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

1 participant