API results for interfaces/virtual interfaces producing duplicates #2280

Closed
opened 2025-12-29 17:24:27 +01:00 by adam · 3 comments
Owner

Originally created by @zmaster7 on GitHub (Jan 10, 2019).

Environment

  • Python version: 3.5.2
  • NetBox version: 2.5.1

Description

I am using Powershell to loop through the API and return all the interfaces via the "next" URL:

$API = "https://hostname/api/dcim/interfaces/"
$Results = @{}

$Results = While ( $API ) { 
	$Get = Invoke-RestMethod -Uri $API -Headers $Headers -Method Get
	$API = $Get.next
	$Get.results
}

Duplicate ids are being returned for both /api/dcim/interfaces/ and /api/virtualization/interfaces/ calls. For any other API path I have tested it has been fine (even with counts upward of 400+). My /api/dcim/interfaces call returns 3149 results (which is correct), and the amount of duplicate results do change if I change the limit parameter (the total result counts do NOT change, therefore some interfaces are not returned)

Examples:
Default limit (50) = 103 duplicate ids
limit of 125 = 48 duplicates
limit of 250 = 9 duplicate
limit of 500 = 3 duplicates
limit of 1000 = 1 duplicate

I am using the following to determine the number of duplicates:

$Results | Group-Object id | ? { $_.count -ge 2 } | Measure-Object

If I query the database I can confirm there are no duplicates.

Originally created by @zmaster7 on GitHub (Jan 10, 2019). ### Environment * Python version: 3.5.2 * NetBox version: 2.5.1 <!-- Describe in detail the steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). --> ### Description I am using Powershell to loop through the API and return all the interfaces via the "next" URL: ``` $API = "https://hostname/api/dcim/interfaces/" $Results = @{} $Results = While ( $API ) { $Get = Invoke-RestMethod -Uri $API -Headers $Headers -Method Get $API = $Get.next $Get.results } ``` Duplicate ids are being returned for both /api/dcim/interfaces/ and /api/virtualization/interfaces/ calls. For any other API path I have tested it has been fine (even with counts upward of 400+). My /api/dcim/interfaces call returns 3149 results (which is correct), and the amount of duplicate results do change if I change the limit parameter (the total result counts do NOT change, therefore some interfaces are not returned) Examples: Default limit (50) = 103 duplicate ids limit of 125 = 48 duplicates limit of 250 = 9 duplicate limit of 500 = 3 duplicates limit of 1000 = 1 duplicate I am using the following to determine the number of duplicates: `$Results | Group-Object id | ? { $_.count -ge 2 } | Measure-Object` If I query the database I can confirm there are no duplicates.
adam closed this issue 2025-12-29 17:24:27 +01:00
Author
Owner

@zmaster7 commented on GitHub (Jan 10, 2019):

To add some more to the troubleshooting, I broke down each of the API calls into an array (each part an individual call) and compared them to find the duplicates -

The results were laid out in an array like (total of 63 calls to gather all 3149 objects):

$Results[1] = "results" of call to /api/dcim/interfaces/
$Results[2] = "results" of call to /api/dcim/interfaces/?limit=50&offset=50
$Results[3] = "results" of call to /api/dcim/interfaces/?limit=50&offset=100
$Results[4] = "results" of call to /api/dcim/interfaces/?limit=50&offset=150
etc.

Here are the results of the comparison (rather interesting):

image

If I set the limit to 1000, the sole duplicate exists between the first and second call.

@zmaster7 commented on GitHub (Jan 10, 2019): To add some more to the troubleshooting, I broke down each of the API calls into an array (each part an individual call) and compared them to find the duplicates - The results were laid out in an array like (total of 63 calls to gather all 3149 objects): ``` $Results[1] = "results" of call to /api/dcim/interfaces/ $Results[2] = "results" of call to /api/dcim/interfaces/?limit=50&offset=50 $Results[3] = "results" of call to /api/dcim/interfaces/?limit=50&offset=100 $Results[4] = "results" of call to /api/dcim/interfaces/?limit=50&offset=150 etc. ``` Here are the results of the comparison (rather interesting): ![image](https://user-images.githubusercontent.com/46574676/50995931-92d95780-14ee-11e9-9c1c-4c7c7857bd41.png) If I set the limit to 1000, the sole duplicate exists between the first and second call.
Author
Owner

@jeremystretch commented on GitHub (Jan 11, 2019):

Please provide the exact steps someone else can take to replicate the issue on a standard installation, beginning with the creation of objects and including the raw API requests that are being made (e.g. using curl) which result in duplicate objects.

@jeremystretch commented on GitHub (Jan 11, 2019): Please provide the exact steps someone else can take to replicate the issue on a standard installation, beginning with the creation of objects and including the raw API requests that are being made (e.g. using `curl`) which result in duplicate objects.
Author
Owner

@zmaster7 commented on GitHub (Jan 15, 2019):

It looks like it may have been a result of one of the upgrades, as I am not able to replicate it in a new install of v2.5.3.

For what it is worth:
I created 400 devices and 10 interfaces per device (4,000 total) via the following:

for x in {1..400}
do
	UPLOAD="{\"name\":\"device-$x\",\"device_type\":1,\"device_role\":1,\"site\":1}"
	curl -X POST -H "Authorization: Token INSERTTOKENHERE" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" http://hostname/api/dcim/devices/ --data $UPLOAD

	for y in {1..10}
	do
		UPLOAD="{\"name\":\"device-$x-int-$y\",\"device\":$x}"
		curl -X POST -H "Authorization: Token INSERTTOKENHERE" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" http://hostname/api/dcim/interfaces/ --data $UPLOAD
	done
done

I also tested deleting and re-creating sections of interfaces to try and trigger the issue to no avail.
example:

for y in {500..1000}
do
	curl -X DELETE -H "Authorization: Token INSERTTOKENHERE" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" "http://hostname/api/dcim/interfaces/$y/"
done

for x in {50..100}
do
	for y in {1..10}
	do
		UPLOAD="{\"name\":\"device-$x-int-$y\",\"device\":$x}"
		curl -X POST -H "Authorization: Token INSERTTOKENHERE" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" http://hostname/api/dcim/interfaces/ --data $UPLOAD
	done
done

You can close this issue. Thanks.

@zmaster7 commented on GitHub (Jan 15, 2019): It looks like it may have been a result of one of the upgrades, as I am not able to replicate it in a new install of v2.5.3. For what it is worth: I created 400 devices and 10 interfaces per device (4,000 total) via the following: ``` for x in {1..400} do UPLOAD="{\"name\":\"device-$x\",\"device_type\":1,\"device_role\":1,\"site\":1}" curl -X POST -H "Authorization: Token INSERTTOKENHERE" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" http://hostname/api/dcim/devices/ --data $UPLOAD for y in {1..10} do UPLOAD="{\"name\":\"device-$x-int-$y\",\"device\":$x}" curl -X POST -H "Authorization: Token INSERTTOKENHERE" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" http://hostname/api/dcim/interfaces/ --data $UPLOAD done done ``` I also tested deleting and re-creating sections of interfaces to try and trigger the issue to no avail. example: ``` for y in {500..1000} do curl -X DELETE -H "Authorization: Token INSERTTOKENHERE" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" "http://hostname/api/dcim/interfaces/$y/" done for x in {50..100} do for y in {1..10} do UPLOAD="{\"name\":\"device-$x-int-$y\",\"device\":$x}" curl -X POST -H "Authorization: Token INSERTTOKENHERE" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" http://hostname/api/dcim/interfaces/ --data $UPLOAD done done ``` You can close this issue. Thanks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2280