Netbox: Device components duplicated in paginated API responses when not filtered by device

Created on 28 Feb 2019  路  1Comment  路  Source: netbox-community/netbox

Environment

  • Python version: 3.6.7
  • NetBox version: 2.5.7

Steps to Reproduce

1.GET /api/dcim/console-ports/?limit=200&offset=0
2.GET /api/dcim/console-ports/?limit=200&offset=200 (and continue to have all)

Expected Behavior

List all console ports

Observed Behavior

If we compare all page, we have duplicate console ports and we have missing console ports.
If we do a Get with a limit greater than the number of console ports, we don't have any duplicate or missing console ports.

accepted bug

Most helpful comment

This applies to all device components and component templates (except interfaces), not just console ports. Code to reproduce:

import requests

url='http://localhost:8000/api/dcim/console-ports/'
params = {
    'limit': 200,
    'offset': 0,
}
r = requests.get(url, params)
ids = [obj['id'] for obj in r.json()['results']]

params['offset'] = 200
r = requests.get(url, params)
for obj in r.json()['results']:
    if obj['id'] in ids:
        print("Duplicate ID: {}".format(obj['id']))

The issue here is that DeviceComponentManager.get_queryset() orders objects only by name, not by unique ID. This is fine when the list is filtered by device, but does not ensure deterministic ordering when the query includes objects with the same name. Nice catch!

>All comments

This applies to all device components and component templates (except interfaces), not just console ports. Code to reproduce:

import requests

url='http://localhost:8000/api/dcim/console-ports/'
params = {
    'limit': 200,
    'offset': 0,
}
r = requests.get(url, params)
ids = [obj['id'] for obj in r.json()['results']]

params['offset'] = 200
r = requests.get(url, params)
for obj in r.json()['results']:
    if obj['id'] in ids:
        print("Duplicate ID: {}".format(obj['id']))

The issue here is that DeviceComponentManager.get_queryset() orders objects only by name, not by unique ID. This is fine when the list is filtered by device, but does not ensure deterministic ordering when the query includes objects with the same name. Nice catch!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robbagithub picture robbagithub  路  3Comments

VictorJ76 picture VictorJ76  路  3Comments

billyzoellers picture billyzoellers  路  3Comments

hellerve picture hellerve  路  3Comments

hoalex picture hoalex  路  3Comments