Improve error handling on available-prefixes API endpoint #2276

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

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

Environment

  • Python version: 3.5.2
  • NetBox version: 2.5.2

Steps to Reproduce

  1. Create a new prefix and note its primary key
  2. Send an API request to automatically provision a new prefix within that prefix, specifying the prefix_length as a string. For example:
curl -X POST \
-H "Authorization: Token <token>" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
https://netbox/api/ipam/prefixes/<pk>/available-prefixes/ \
--data '{"prefix_length": "28", "is_pool": true}'

Expected Behavior

NetBox should return a validation error, indicating that prefix_length must be an integer.

Observed Behavior

A TypeError exception is raised, resulting in a server error.

The ideal fix for this is to adopt an actual API serializer to handle the requested prefixes, instead of processing it as a raw data dict like we do now.

Originally created by @jeremystretch on GitHub (Jan 10, 2019). ### Environment * Python version: 3.5.2 * NetBox version: 2.5.2 ### Steps to Reproduce 1. Create a new prefix and note its primary key 2. Send an API request to automatically provision a new prefix within that prefix, specifying the `prefix_length` as a string. For example: ``` curl -X POST \ -H "Authorization: Token <token>" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ https://netbox/api/ipam/prefixes/<pk>/available-prefixes/ \ --data '{"prefix_length": "28", "is_pool": true}' ``` ### Expected Behavior NetBox should return a validation error, indicating that `prefix_length` must be an integer. ### Observed Behavior A `TypeError` exception is raised, resulting in a server error. The ideal fix for this is to adopt an actual API serializer to handle the requested prefixes, instead of processing it as a raw data dict like we do now.
adam added the type: bugstatus: accepted labels 2025-12-29 17:24:26 +01:00
adam closed this issue 2025-12-29 17:24:26 +01:00
Author
Owner

@hellerve commented on GitHub (May 27, 2019):

Is this something I could work on or is there already work underway to fix it?

@hellerve commented on GitHub (May 27, 2019): Is this something I could work on or is there already work underway to fix it?
Author
Owner

@jeremystretch commented on GitHub (May 27, 2019):

@hellerve I think the approach needed here is to write a generic (non-model) serializer to represent the prefix being requested. This would provide native validation of fields like prefix_length and vrf. Feel free to poke around!

@jeremystretch commented on GitHub (May 27, 2019): @hellerve I _think_ the approach needed here is to write a generic (non-model) serializer to represent the prefix being requested. This would provide native validation of fields like `prefix_length` and `vrf`. Feel free to poke around!
Author
Owner

@hellerve commented on GitHub (May 28, 2019):

I suppose this should also be done for available-ips, then?

@hellerve commented on GitHub (May 28, 2019): I suppose this should also be done for `available-ips`, then?
Author
Owner

@hellerve commented on GitHub (May 28, 2019):

I added a POC that passes all the tests and is a little better, but I don’t think all the fields are in there as of yet. I’ll make a PR tomorrow once I figure out what else needs to go in there.

@hellerve commented on GitHub (May 28, 2019): I added a POC that passes all the tests and is a little better, but I don’t think all the fields are in there as of yet. I’ll make a PR tomorrow once I figure out what else needs to go in there.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2276