FilterChoiceField forces queryset evaluation despite rendering only a default choice #3287

Closed
opened 2025-12-29 18:27:26 +01:00 by adam · 1 comment
Owner

Originally created by @jeremystretch on GitHub (Feb 6, 2020).

Environment

  • Python version: 3.6.9
  • NetBox version: 2.7.4

Steps to Reproduce

  1. Enable debugging
  2. Navigate to a device and select "Add components" > "Console port"
  3. Inspect the database queries being made

(This can be replicated anywhere the APISelect widget is in use; this is just one concise example.)

Expected Behavior

Because the APISelect widget populates only a single initial choice (if one exists) and not every available option, it should not be querying the database for all options.

Observed Behavior

A query is made for all field options, even though they are unnecessary to render the widget.

Originally created by @jeremystretch on GitHub (Feb 6, 2020). ### Environment * Python version: 3.6.9 * NetBox version: 2.7.4 ### Steps to Reproduce 1. Enable debugging 2. Navigate to a device and select "Add components" > "Console port" 3. Inspect the database queries being made (This can be replicated anywhere the APISelect widget is in use; this is just one concise example.) ### Expected Behavior Because the APISelect widget populates only a single initial choice (if one exists) and not every available option, it should not be querying the database for all options. ### Observed Behavior A query is made for all field options, even though they are unnecessary to render the widget.
adam added the type: bugstatus: accepted labels 2025-12-29 18:27:26 +01:00
adam closed this issue 2025-12-29 18:27:27 +01:00
Author
Owner

@hSaria commented on GitHub (Feb 10, 2020):

I think with this change, it should be okay to remove the custom template
885ea8a4d5/netbox/utilities/forms.py (L263-L264)

@hSaria commented on GitHub (Feb 10, 2020): I think with this change, it should be okay to remove the custom template https://github.com/netbox-community/netbox/blob/885ea8a4d5f7191afd564501e3b013b1c9ff85f6/netbox/utilities/forms.py#L263-L264
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3287