Query for advanced object selector does not use query_params defined on input
Deployment Type
NetBox Cloud
NetBox Version
v4.2.4
Python Version
3.12
Steps to Reproduce
Create two Sites and attempt to create a Virtual Machine scoped to conflicting Sites for fields site and cluster.
- Create 2 Sites: "My Site" and "Your Site"
- Create a Cluster Role: "My Role"
- Create a Cluster ("My Cluster") and assign it to "My Site"
- Create a Virtual Machine and assign it to "Your Site" and use the advanced object selector for the Cluster input to assign it to "My Cluster"
Expected Behavior
User should be unable to assign "My Cluster" because the Cluster is scoped to "My Site" and the Virtual Machine is scoped to "Your Site".
The query_params defined on the Virtual Machine's cluster input should prevent this: https://github.com/netbox-community/netbox/blob/beb0aff6569ca2f6656c765077cba68d69386453/netbox/virtualization/forms/model_forms.py#L187-L189
Observed Behavior
While the cluster input itself does filter out the "My Cluster" option, selecting the Advanced Object Selector allows the selection of "My Cluster". Attempting to create the Virtual Machine scoped to the "My Cluster" Cluster returns an error:
The scope of this issue is currently limited to form inputs that utilize both the selector=True and query_params={...} attributes. But with the acceptance of issues #18138 and #17944 this could be impactful to user-defined scripts and custom fields.
Upon initial review, it appears that we'll need to pass the query parameters associated with the form field when sending the HTMX request to populate the advanced selection widget. This might be a bit tricky, as (unlike the field itself) we're not applying these filters directly, but rather passing them for reference to be employed when initializing the widget form. But it should be doable.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.
This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.