Tag filtering in custom scripts not working #4055

Closed
opened 2025-12-29 18:32:52 +01:00 by adam · 3 comments
Owner

Originally created by @Kircheneer on GitHub (Sep 1, 2020).

Environment

  • Python version: 3.7.9
  • NetBox version: 2.9.2

Steps to Reproduce

  1. Create any number of Prefixes with a specific tag (for this example it will be 'auto_assign' with id 9)
  2. Create a custom Script with a ObjectVar for a Prefix field:
prefix = ObjectVar(
    queryset=Prefix.objects.filter(tags__name='auto_assign'),  # Works fine in nbshell  
    display_field='prefix'
)
  1. View the custom script field in the GUI

Expected Behavior

The queryset filters to display only those prefixes that have this specific tag

Observed Behavior

All prefixes were shown.

Originally created by @Kircheneer on GitHub (Sep 1, 2020). ### Environment * Python version: 3.7.9 * NetBox version: 2.9.2 ### Steps to Reproduce 1. Create any number of Prefixes with a specific tag (for this example it will be 'auto_assign' with id 9) 2. Create a custom Script with a ObjectVar for a Prefix field: ``` prefix = ObjectVar( queryset=Prefix.objects.filter(tags__name='auto_assign'), # Works fine in nbshell display_field='prefix' ) ``` 3. View the custom script field in the GUI ### Expected Behavior The queryset filters to display only those prefixes that have this specific tag ### Observed Behavior All prefixes were shown.
adam closed this issue 2025-12-29 18:32:52 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 1, 2020):

Please see the ObjectVar documentation for the correct way to implement the desired behavior on NetBox v2.9.

@jeremystretch commented on GitHub (Sep 1, 2020): Please see the [ObjectVar documentation](https://netbox.readthedocs.io/en/stable/additional-features/custom-scripts/#objectvar) for the correct way to implement the desired behavior on NetBox v2.9.
Author
Owner

@Kircheneer commented on GitHub (Sep 1, 2020):

Sorry, forgot to mention I tried that, too:

prefix = ObjectVar(
    model=Prefix,
    display_field='prefix',
    query_params={
        'tags__name': 'auto_assign'
    }
)

This returns all prefixes - unfiltered - too. I also tried it with query_params={'tags': 9} which lead to the same result (9 being the id of the 'auto_assign' tag.

@Kircheneer commented on GitHub (Sep 1, 2020): Sorry, forgot to mention I tried that, too: ``` prefix = ObjectVar( model=Prefix, display_field='prefix', query_params={ 'tags__name': 'auto_assign' } ) ``` This returns all prefixes - unfiltered - too. I also tried it with `query_params={'tags': 9}` which lead to the same result (9 being the id of the 'auto_assign' tag.
Author
Owner

@jeremystretch commented on GitHub (Sep 1, 2020):

query_params appends query parameters to the URL used when making an API request for the objects. It uses the same format as when filtering a list of objects in the web UI. Try that first, then check the resulting URL to determine what parameters need to be applied.

@jeremystretch commented on GitHub (Sep 1, 2020): `query_params` appends query parameters to the URL used when making an API request for the objects. It uses the same format as when filtering a list of objects in the web UI. Try that first, then check the resulting URL to determine what parameters need to be applied.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4055