Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jeremystretch opened this issue Feb 6, 2020 · 1 comment · Fixed by #4128
Closed
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@jeremystretch
Copy link
Member

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.

@jeremystretch jeremystretch added type: bug A confirmed report of unexpected behavior in the application status: accepted This issue has been accepted for implementation labels Feb 6, 2020
@hSaria
Copy link
Contributor

hSaria commented Feb 10, 2020

I think with this change, it should be okay to remove the custom template

# Only preload the selected option(s); new options are dynamically displayed and added via the API
template_name = 'widgets/select_api.html'

jeremystretch added a commit that referenced this issue Feb 10, 2020
@jeremystretch jeremystretch changed the title APISelect forces queryset evaluation despite rendering only a default choice FilterChoiceField forces queryset evaluation despite rendering only a default choice Feb 10, 2020
jeremystretch added a commit that referenced this issue Feb 10, 2020
…ance

Closes #4108: Extraneous queryset evaluation by FilterChoiceFields
@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants