Static and Dynamic Query Params Are Copied between APISelect
Widgets within Separate Forms
#7176
Labels
status: under review
Further discussion is needed to determine this issue's scope and/or implementation
type: bug
A confirmed report of unexpected behavior in the application
NetBox version
v3.0.1
Python version
3.8
Steps to Reproduce
1
2
untagged_vlans
field for Device `. It should look like this:If you refresh Device 2's tab, you should see the same result.
This can also be replicated in
nbshell
:After digging into why, I found that when each field is initialize, Django deep copies the field's widget. This uses the
__deepcopy__
method on the widget. SinceAPISelect
subclassesdjango.forms.Select
and notdjango.forms.Widget
, that deep copy takes place via this method.To fix the issue, adding a
__deepcopy__
method onAPISelect
that runs the built-in__deepcopy__
and creates newstatic_params
anddynamic_params
seems to do the trick:Expected Behavior
static_params
anddynamic_params
are custom properties added to track the widget's dynamic and static query parameters. Historically, this was tracked directly on the underlying Widget (field['<field_name>'].widget.attrs
), and overridden by Django after the deep copy. While we could semi-replicate this behavior with the newstatic_params
anddynamic_params
properties, it seems to be the fact that those properties are copied over to begin with is not desired. I could see getting into a situation in the future where these properties being copied over could cause some weird bugs. To me, it makes more sense to exclude these from the widget copy.Essentially, I'd like a thumbs up on this approach, or a suggestion for a different approach in case there are things I haven't considered.
Observed Behavior
By default, any custom properties defined on a field that are not excluded from deep copying are copied over between forms. See above Steps to Reproduce for examples.
The text was updated successfully, but these errors were encountered: