Interface API Query Excludes Newly-Added Virtual Interfaces #4851

Closed
opened 2025-12-29 19:21:15 +01:00 by adam · 2 comments
Owner

Originally created by @thatmattlove on GitHub (Apr 30, 2021).

NetBox version

v2.11.2

Python version

3.8

Steps to Reproduce

Note: I'm actually using the Netbox demo to reproduce this. While the data will reset, these values are currently active and valid as of this writing, and I'm using this device to perform the tests.

  1. Create a new interface on a device and set the type to Virtual, making note of the device's ID/PK. In this example, the device ID is 15.

  2. Query the API like so:

curl -H 'Authorization:Token <token>' https://<netbox host>/api/dcim/interfaces/?device_id=15

You'll notice that the response contains physical interfaces, but not virtual interfaces.

  1. In contrast, you can slightly adjust the API query like so:
curl -H 'Authorization:Token <token>' https://<netbox host>/api/dcim/interfaces/?device_id=15&id=1114

Observe that the response now contains the interface in question with the added id=1114 query parameter.

  1. This does not occur with physical interfaces. Now add a new interface to the same device, for example: GigabitEthernet2/0/1 and select a 1000BASE-T (1GE) interface type. If you query the API like so :
curl -H 'Authorization:Token <token>' https://<netbox host>/api/dcim/interfaces/?device_id=15

Observe the newly added GigabitEthernet2/0/1 interface in your response.

  1. This does not occur with virtual interfaces that already existed. For example, I have a production instance of Netbox that was recently upgraded to v2.11.2. In this production instance there are devices which have had virtual interfaces since version 2.9 (can't recall the patch release number), and these interfaces do show up in the response. But, when adding a new virtual interface, only the new interfaces seem to be excluded.

Expected Behavior

An API query such as /api/dcim/interfaces/?device_id=15 should respond with all interfaces related to device 15.

Observed Behavior

See steps to reproduce for observations. Here are a few extra things I tried:

  • Disabled caching; same result
  • This does not occur in the UI, only the API (also reproducable via Swagger)
  • Using nbshell, ran essentially the same query that dcim.api.views.InterfaceViewSet appears to run, i.e. utilities.filters.InterfaceFilterSet. Via nbshell, all interfaces including the newly added virtual ones are returned:
>>> queryset = Interface.objects.prefetch_related('device', 'parent', 'lag', '_path__destination', 'cable', '_cable_peer', 'ip_addresses', 'tags')
>>> for obj in queryset.filter(device_id=15):
...       print(f"{obj.pk}: {str(obj)} ({obj.type})")
...
# omitted for brevity
267: GigabitEthernet1/0/47 (1000base-t)
268: GigabitEthernet1/0/48 (1000base-t)
1340: GigabitEthernet2/0/1 (1000base-t) # <- Test physical interface I created
269: GigabitEthernet0 (1000base-t)
836: Po1 (lag)
270: STACK0 (cisco-stackwise)
271: STACK1 (cisco-stackwise)
1338: test (virtual) # <- Test virtual interface I created
Originally created by @thatmattlove on GitHub (Apr 30, 2021). ### NetBox version v2.11.2 ### Python version 3.8 ### Steps to Reproduce _Note: I'm actually using the Netbox demo to reproduce this. While the data will reset, these values are currently active and valid as of this writing, and I'm using [this device](https://demo.netbox.dev/dcim/devices/15/) to perform the tests._ 1. Create a new interface on a device and set the type to `Virtual`, making note of the device's ID/PK. In this example, the device ID is 15. 2. Query the API like so: ```bash curl -H 'Authorization:Token <token>' https://<netbox host>/api/dcim/interfaces/?device_id=15 ``` You'll notice that the response contains physical interfaces, but not virtual interfaces. 3. In contrast, you can slightly adjust the API query like so: ```bash curl -H 'Authorization:Token <token>' https://<netbox host>/api/dcim/interfaces/?device_id=15&id=1114 ``` Observe that the response now contains the interface in question with the added `id=1114` query parameter. 4. This does _not_ occur with physical interfaces. Now add a new interface to the same device, for example: `GigabitEthernet2/0/1` and select a `1000BASE-T (1GE)` interface type. If you query the API like so : ```bash curl -H 'Authorization:Token <token>' https://<netbox host>/api/dcim/interfaces/?device_id=15 ``` Observe the newly added `GigabitEthernet2/0/1` interface in your response. 5. This does _not_ occur with virtual interfaces that already existed. For example, I have a production instance of Netbox that was recently upgraded to v2.11.2. In this production instance there are devices which have had virtual interfaces since version 2.9 (can't recall the patch release number), and these interfaces _do_ show up in the response. But, when adding a new virtual interface, only the new interfaces seem to be excluded. ### Expected Behavior An API query such as `/api/dcim/interfaces/?device_id=15` should respond with **all** interfaces related to device 15. ### Observed Behavior See steps to reproduce for observations. Here are a few extra things I tried: - Disabled caching; same result - This does not occur in the UI, only the API (also reproducable via Swagger) - Using nbshell, ran essentially the same query that `dcim.api.views.InterfaceViewSet` appears to run, i.e. `utilities.filters.InterfaceFilterSet`. Via nbshell, all interfaces including the newly added virtual ones are returned: ```python >>> queryset = Interface.objects.prefetch_related('device', 'parent', 'lag', '_path__destination', 'cable', '_cable_peer', 'ip_addresses', 'tags') >>> for obj in queryset.filter(device_id=15): ... print(f"{obj.pk}: {str(obj)} ({obj.type})") ... # omitted for brevity 267: GigabitEthernet1/0/47 (1000base-t) 268: GigabitEthernet1/0/48 (1000base-t) 1340: GigabitEthernet2/0/1 (1000base-t) # <- Test physical interface I created 269: GigabitEthernet0 (1000base-t) 836: Po1 (lag) 270: STACK0 (cisco-stackwise) 271: STACK1 (cisco-stackwise) 1338: test (virtual) # <- Test virtual interface I created ```
adam added the type: bug label 2025-12-29 19:21:15 +01:00
adam closed this issue 2025-12-29 19:21:15 +01:00
Author
Owner

@thatmattlove commented on GitHub (Apr 30, 2021):

I'm not too bright apparently — this is due to default pagination of 50, and is resolved by adding &limit=0 to the query parameters.

@thatmattlove commented on GitHub (Apr 30, 2021): I'm not too bright apparently — this is due to default pagination of 50, and is resolved by adding `&limit=0` to the query parameters.
Author
Owner

@jeremystretch commented on GitHub (Apr 30, 2021):

That was such a beautiful bug report too. I'm kinda sad it wasn't real. 😢

@jeremystretch commented on GitHub (Apr 30, 2021): That was such a beautiful bug report too. I'm kinda sad it wasn't real. :cry:
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4851