API call /ipam/prefixes/{id}/available-prefixes/ returns empty list when there are no child prefixes #3929

Closed
opened 2025-12-29 18:32:07 +01:00 by adam · 3 comments
Owner

Originally created by @gusmb on GitHub (Aug 1, 2020).

Environment

  • Python version: 3.8.2
  • NetBox version: 2.8.8

Steps to Reproduce

  1. Create an IP Prefix with no child prefixes
  2. API GET call to retrieve the list of available prefixes
    (e.g. curl -X GET "http://localhost:8000/api/ipam/prefixes/1/available-prefixes/")

Expected Behavior

The result should be a list with a single entry, the entire parent prefix, since no child prefixes are created.

Observed Behavior

The returned list is empty instead, which leads to confusion since this could also mean that there are no child prefixes available to allocate.

NOTE: The behavior is correct as soon as there is at least 1 child prefix created. In this case the available-prefixes API call returns a list as expected, ordered from smaller to bigger prefixes.

Originally created by @gusmb on GitHub (Aug 1, 2020). ### Environment * Python version: 3.8.2 * NetBox version: 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 an IP Prefix with no child prefixes 2. API GET call to retrieve the list of available prefixes (e.g. curl -X GET "http://localhost:8000/api/ipam/prefixes/1/available-prefixes/") <!-- What did you expect to happen? --> ### Expected Behavior The result should be a list with a single entry, the entire parent prefix, since no child prefixes are created. <!-- What happened instead? --> ### Observed Behavior The returned list is empty instead, which leads to confusion since this could also mean that there are no child prefixes available to allocate. NOTE: The behavior is correct as soon as there is at least 1 child prefix created. In this case the available-prefixes API call returns a list as expected, ordered from smaller to bigger prefixes.
adam closed this issue 2025-12-29 18:32:08 +01:00
Author
Owner

@gusmb commented on GitHub (Aug 1, 2020):

Closing, the last leading '/' was the problem. Not using the'/' at the end causes an empty return in all cases

@gusmb commented on GitHub (Aug 1, 2020): Closing, the last leading '/' was the problem. Not using the'/' at the end causes an empty return in all cases
Author
Owner

@jeremystretch commented on GitHub (Aug 3, 2020):

Be sure to take note of the HTTP response code. In this case, the response is a 302 redirecting the client to the canonical endpoint (with the trailing slash), hence the empty body.

@jeremystretch commented on GitHub (Aug 3, 2020): Be sure to take note of the HTTP response code. In this case, the response is a 302 redirecting the client to the canonical endpoint (with the trailing slash), hence the empty body.
Author
Owner

@gusmb commented on GitHub (Aug 3, 2020):

Thanks Jeremy,
Cheers

@gusmb commented on GitHub (Aug 3, 2020): Thanks Jeremy, Cheers
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3929