API return duplicates rack reservation for long list of rack reservation #3973

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

Originally created by @pradiptama on GitHub (Aug 12, 2020).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: Python 3.6
  • NetBox version: Netbox 2.8.8

Steps to Reproduce

  1. Create many rack reservation (say more than 500) at same time using API that "created" have same date.
  2. Extract rack reservation page using API where limit=25. Sample URL https://localhost/api/dcim/rack-reservations?limit=25
  3. Store result in a python list and check for total number of object and total number of distinct objects

Sample code

import requests
url = 'https://localhost/api/dcim/rack-reservations?limit=25'
results = []
more = True
while more:
    resp = requests.get(url).json()
    url = resp['next']
    results.extend(resp['results'])
    if not url:
        more = False

print(f'total reservations retrieved: {len(results)}')
print(f"total unique IDs retrieved: {len(set([r['id'] for r in results]))}")

Expected Behavior

"total reservations retrieved" should be same as "total unique IDs retrieved"

Observed Behavior

Number of "total unique IDs retrieved" is less than "total reservations retrieved".

Originally created by @pradiptama on GitHub (Aug 12, 2020). Originally assigned to: @jeremystretch on GitHub. <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report, and that any plugins have been disabled. --> ### Environment * Python version: Python 3.6 * NetBox version: Netbox 2.8.8 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> ### Steps to Reproduce 1. Create many rack reservation (say more than 500) at same time using API that "created" have same date. 2. Extract rack reservation page using API where limit=25. Sample URL https://localhost/api/dcim/rack-reservations?limit=25 3. Store result in a python list and check for total number of object and total number of distinct objects Sample code ``` import requests url = 'https://localhost/api/dcim/rack-reservations?limit=25' results = [] more = True while more: resp = requests.get(url).json() url = resp['next'] results.extend(resp['results']) if not url: more = False print(f'total reservations retrieved: {len(results)}') print(f"total unique IDs retrieved: {len(set([r['id'] for r in results]))}") ``` <!-- What did you expect to happen? --> ### Expected Behavior "total reservations retrieved" should be same as "total unique IDs retrieved" <!-- What happened instead? --> ### Observed Behavior Number of "total unique IDs retrieved" is less than "total reservations retrieved".
adam added the type: bugstatus: accepted labels 2025-12-29 18:32:23 +01:00
adam closed this issue 2025-12-29 18:32:23 +01:00
Author
Owner

@pradiptama commented on GitHub (Aug 12, 2020):

Seems like this issue because rack reservation get sorted on "created" field and in case of many duplicate the pagination (LIMIT and OFFSET in the DB query) sometime pick up the same records in the later query and missing other records. The simple solution should be order by "id" as here (but I did not tested that)

@pradiptama commented on GitHub (Aug 12, 2020): Seems like this issue because rack reservation get sorted on "created" field and in case of many duplicate the pagination (LIMIT and OFFSET in the DB query) sometime pick up the same records in the later query and missing other records. The simple solution should be order by "id" as [here](https://github.com/netbox-community/netbox/blob/3c395e7c9f56ff8927bbc154b7dbb2d0573e7c00/netbox/dcim/models/__init__.py#L829) (but I did not tested that)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3973