ChainedFieldsMixin fails to restrict queryset when form validation fails #2546

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

Originally created by @jeremystretch on GitHub (Apr 25, 2019).

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.

Originally created by @jeremystretch on GitHub (Apr 25, 2019). ### 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.
adam added the type: bugstatus: accepted labels 2025-12-29 18:19:50 +01:00
adam closed this issue 2025-12-29 18:19:51 +01:00
Author
Owner

@hellerve commented on GitHub (May 27, 2019):

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.

@hellerve commented on GitHub (May 27, 2019): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2546