Skip to content

query params attribute is shared between form instances. #216

Description

@sjoerdjob

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions