Skip to content

ChainedFieldsMixin fails to restrict queryset when form validation fails #3106

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 Apr 25, 2019 · 1 comment
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.5.2
  • NetBox version: 2.5.10

Steps to Reproduce

  1. Bulk create a large number of IP addresses. 50K seems to be sufficient to replicate using the development server.
  2. Create a new VRF named "MyVRF" and ensure "Enforce unique space" is selected
  3. Create a new IP address 192.0.2.1/32 assigned to MyVRF
  4. Attempt to create a second new IP address192.0.2.1/32 assigned to MyVRF

Expected Behavior

The creation should fail and immediately return the form with the original data and a validation error.

Observed Behavior

NetBox takes a very long time to return the response. (With debugging enabled, it never returns.) I believe what's happening is that ChainedFieldsMixin is not filtering the queryset of the nat_inside field due to the failed form validation. This means the field is rendered with the queryset IPAddress.objects.all(), which will take a long time to render when a large number of IPAddress objects exist.

I still need to dig into this some more, but I wanted to make sure the bug was captured. We should also give some more though to how chained fields work in general now that the form widgets are all API-driven.

@jeremystretch jeremystretch added type: bug A confirmed report of unexpected behavior in the application status: accepted This issue has been accepted for implementation labels Apr 25, 2019
@hellerve
Copy link
Contributor

I don’t know how to fix this, but I wanted to chime in to corroborate your hunch: the nat_inside field is in fact not being filtered! I dug into the mixin to figure out how it works, but I’m not quite sure I understand the rules around it; anyway, at least I can say that looking at the code under a debugger, filters_dict is in fact not updated.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 2, 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

No branches or pull requests

2 participants