Query for advanced object selector does not use query_params defined on input #10804

Closed
opened 2025-12-29 21:36:06 +01:00 by adam · 3 comments
Owner

Originally created by @atownson on GitHub (Feb 24, 2025).

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.

  1. Create 2 Sites: "My Site" and "Your Site"
  2. Create a Cluster Role: "My Role"
  3. Create a Cluster ("My Cluster") and assign it to "My Site"
  4. 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: beb0aff656/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:

Image

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.

Originally created by @atownson on GitHub (Feb 24, 2025). ### 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. 1. Create 2 Sites: "My Site" and "Your Site" 2. Create a Cluster Role: "My Role" 3. Create a Cluster ("My Cluster") and assign it to "My Site" 4. 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: ![Image](https://github.com/user-attachments/assets/66b72aa0-c99c-4d99-af8a-3678c1180f69) 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.
adam added the type: bugstatus: needs ownerpending closureseverity: low labels 2025-12-29 21:36:06 +01:00
adam closed this issue 2025-12-29 21:36:06 +01:00
Author
Owner

@jeremystretch commented on GitHub (Feb 28, 2025):

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.

@jeremystretch commented on GitHub (Feb 28, 2025): 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.
Author
Owner

@github-actions[bot] commented on GitHub (May 30, 2025):

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.

@github-actions[bot] commented on GitHub (May 30, 2025): 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](https://github.com/netbox-community/netbox/blob/main/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Jun 29, 2025):

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.

@github-actions[bot] commented on GitHub (Jun 29, 2025): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10804