Interface query via API returns too many interfaces since v2.11.2 #4847

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

Originally created by @cs-1 on GitHub (Apr 29, 2021).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v2.11.2

Python version

3.8

Steps to Reproduce

  1. Create at least two devices with the naming scheme "myname/1" and "myname/2" (number after "/" corresponds with the stack member ID in our case).
  2. Create a virtual chassis called "myname" and add devices "myname/1" and "myname/2" as members. Do not make one of the members a master.
  3. Query NetBox using the following GET request:
https://<netbox-server>/api/dcim/interfaces/?device=myname%2F1

Expected Behavior

In NetBox v2.11.1 the above query would produce only interface data of the VC member "myname/1".

Observed Behavior

After upgrading to v2.11.2 this produces the interfaces of all devices in the same virtual chassis despite none of the VC members being master. Please note that this query also produces all interfaces of all devices when querying "myname/2"'s interfaces.

We can clearly pin this on some change in v2.11.2. We used a VM snapshot of the v2.11.1 server to verify this and I can confirm that this behaviour was not present in v2.11.1.

Deleting the virtual chassis "myname" will immediately remedy this problem. So this is related to the fact that the devices are members of a virtual chassis.

This issue can be reproduced in Swagger.

Originally created by @cs-1 on GitHub (Apr 29, 2021). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v2.11.2 ### Python version 3.8 ### Steps to Reproduce 1. Create at least two devices with the naming scheme "myname/1" and "myname/2" (number after "/" corresponds with the stack member ID in our case). 2. Create a virtual chassis called "myname" and add devices "myname/1" and "myname/2" as members. **Do not** make one of the members a master. 3. Query NetBox using the following GET request: ``` https://<netbox-server>/api/dcim/interfaces/?device=myname%2F1 ``` ### Expected Behavior In NetBox v2.11.1 the above query would produce only interface data of the VC member "myname/1". ### Observed Behavior After upgrading to v2.11.2 this produces the interfaces of **all** devices in the same virtual chassis despite none of the VC members being master. Please note that this query also produces all interfaces of all devices when querying "myname/2"'s interfaces. We can clearly pin this on some change in v2.11.2. We used a VM snapshot of the v2.11.1 server to verify this and I can confirm that this behaviour was not present in v2.11.1. Deleting the virtual chassis "myname" will immediately remedy this problem. So this is related to the fact that the devices are members of a virtual chassis. This issue can be reproduced in Swagger.
adam added the type: bugstatus: accepted labels 2025-12-29 19:21:14 +01:00
adam closed this issue 2025-12-29 19:21:14 +01:00
Author
Owner

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

Please update your steps to reproduce to use raw API requests. We cannot rely on third party tools for bug reproduction.

@jeremystretch commented on GitHub (Apr 29, 2021): Please update your steps to reproduce to use raw API requests. We cannot rely on third party tools for bug reproduction.
Author
Owner

@cs-1 commented on GitHub (Apr 29, 2021):

Sorry, @jeremystretch , I updated the steps to reproduce giving the raw API call. You can actually reproduce it in the Swagger interface, too.

@cs-1 commented on GitHub (Apr 29, 2021): Sorry, @jeremystretch , I updated the steps to reproduce giving the raw API call. You can actually reproduce it in the Swagger interface, too.
Author
Owner

@cs-1 commented on GitHub (Apr 30, 2021):

I've added further clarification. I'll try to find out today which change in v2.11.2 causes this bug.

@cs-1 commented on GitHub (Apr 30, 2021): I've added further clarification. I'll try to find out today which change in v2.11.2 causes this bug.
Author
Owner

@cs-1 commented on GitHub (Apr 30, 2021):

@jeremystretch I found what causes the problem. It seems to be caused by the addition of if_master:

1abaa5e60c/netbox/dcim/models/devices.py (L877)

Removing not if_master or (the way it was before in v2.11.1) fixes the problem, a different way is to change the default to if_master=True. It looks like, due to if_master being False by default, the line

1abaa5e60c/netbox/dcim/models/devices.py (L877)

will always evaluate to True. As far as I can tell if_master is only set to True in 1abaa5e60c/netbox/dcim/views.py and in all other cases the interfaces of all chassis members will always be filtered and shown. This seems to be true for API GET calls to get interfaces of a VC member as well (though this wasn't the case in v2.11.1). It looks like whatever calls this function when using the interfaces API GET request needs to add if_master=True to the function call.

Thanks for looking into this!

@cs-1 commented on GitHub (Apr 30, 2021): @jeremystretch I found what causes the problem. It seems to be caused by the addition of `if_master`: https://github.com/netbox-community/netbox/blob/1abaa5e60c2ecc15ae57db978d389023c136bdf7/netbox/dcim/models/devices.py#L877 Removing `not if_master or ` (the way it was before in v2.11.1) fixes the problem, a different way is to change the default to `if_master=True`. It looks like, due to `if_master` being `False` by default, the line https://github.com/netbox-community/netbox/blob/1abaa5e60c2ecc15ae57db978d389023c136bdf7/netbox/dcim/models/devices.py#L877 will always evaluate to `True`. As far as I can tell `if_master` is only set to `True` in https://github.com/netbox-community/netbox/blob/1abaa5e60c2ecc15ae57db978d389023c136bdf7/netbox/dcim/views.py and in all other cases the interfaces of all chassis members will always be filtered and shown. This seems to be true for API GET calls to get interfaces of a VC member as well (though this wasn't the case in v2.11.1). It looks like whatever calls this function when using the interfaces API GET request needs to add `if_master=True` to the function call. Thanks for looking into this!
Author
Owner

@cs-1 commented on GitHub (May 3, 2021):

Hi @jeremystretch ,

I've spent the weekend thinking about the reasoning behind adding the if_master attribute. If it's ok with you I'd like to ask you some questions about it to understand where to look for a fix for the issue it introduced.

As far as I understand the reason for adding if_master is so that it's possible to query all interfaces of members of the same virtual chassis by using a single call of vc_interfaces() so that LAGs can be configured by using any interface of all virtual chassis members even if none of them is designated as a master chassis. To achieve this, you introduced the if_master variable. To avoid having to change all code calling vc_interfaces() you set it to a default of False so that calling vc_interfaces() without any parameters would behave as it did before which is to only show the interfaces of a particular virtual chassis member and not all interfaces of all chassis members unless the chassis being queried is a master chassis. Is this assumption correct? If it is, the expression in

1abaa5e60c/netbox/dcim/models/devices.py (L877)

needs to be changed to

if self.virtual_chassis and (if_master or self.virtual_chassis.master == self):

That way the code will behave as in v2.11.1 if vc_interfaces() is called without parameter: it will leave the filter untouched an hence only show the interfaces of the virtual chassis member that's being queried and it will only modify the filter to show all interfaces of all virtual chassis members if the chassis queried is the virtual chassis master. If vc_interfaces(if_master=True) is called (as is the case in netbox/dcim/views.py) it will show all interfaces of all virtual chassis members even if the chassis queried isn't a virtual chassis. If I'm wrong and the intention is that a call of vc_interfaces() without parameters will yield all interfaces of all virtual chassis members and it should only return just the interfaces of a virtual chassis member if it's called with parameter as vc_interfaces(if_master=True) then I assume that, when issuing the API GET call, vc_interfaces() is for some reason called without if_master=True.

Sorry for the lengthy post, my insight into the NetBox code isn't very deep hence the questions. I'd really like to help fixing this. The impact of this change is quite dramatic for us because it breaks all of our Ansible playbooks.

@cs-1 commented on GitHub (May 3, 2021): Hi @jeremystretch , I've spent the weekend thinking about the reasoning behind adding the `if_master` attribute. If it's ok with you I'd like to ask you some questions about it to understand where to look for a fix for the issue it introduced. As far as I understand the reason for adding `if_master` is so that it's possible to query all interfaces of members of the same virtual chassis by using a single call of `vc_interfaces()` so that LAGs can be configured by using any interface of all virtual chassis members even if none of them is designated as a master chassis. To achieve this, you introduced the `if_master` variable. To avoid having to change all code calling `vc_interfaces()` you set it to a default of `False` so that calling `vc_interfaces()` without any parameters would behave as it did before which is to only show the interfaces of a particular virtual chassis member and **not** all interfaces of all chassis members **unless** the chassis being queried is a master chassis. Is this assumption correct? If it is, the expression in https://github.com/netbox-community/netbox/blob/1abaa5e60c2ecc15ae57db978d389023c136bdf7/netbox/dcim/models/devices.py#L877 needs to be changed to ``` if self.virtual_chassis and (if_master or self.virtual_chassis.master == self): ``` That way the code will behave as in v2.11.1 if `vc_interfaces()` is called without parameter: it will leave the filter untouched an hence only show the interfaces of the virtual chassis member that's being queried and it will only modify the filter to show all interfaces of all virtual chassis members if the chassis queried is the virtual chassis master. If `vc_interfaces(if_master=True)` is called (as is the case in `netbox/dcim/views.py`) it will show all interfaces of all virtual chassis members even if the chassis queried isn't a virtual chassis. If I'm wrong and the intention is that a call of `vc_interfaces()` without parameters will yield all interfaces of all virtual chassis members and it should only return just the interfaces of a virtual chassis member if it's called with parameter as `vc_interfaces(if_master=True)` then I assume that, when issuing the API GET call, `vc_interfaces()` is for some reason called without `if_master=True`. Sorry for the lengthy post, my insight into the NetBox code isn't very deep hence the questions. I'd really like to help fixing this. The impact of this change is quite dramatic for us because it breaks all of our Ansible playbooks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4847