django-selectable
django-selectable copied to clipboard
query params attribute is shared between form instances.
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