Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

bug: nb.ipam.prefixes.update not working as expected #13

@sboutang

Description

@sboutang

Bug Report

NetBox Python version:
0.1.6

Current behavior:
no update happens

When I use nb.ipam.prefixes.update, no update happens
Expected behavior:
I would expect the http patch data to update and the server to respond with the updated data.

I excpect the server to respond with the changed data
Steps to reproduce:
Below code, is a simple example of just trying to update a description

Related code:

In the below code I am just trying to change the description. It doesn't update using the netbox-python module

when I re-write it to use the requests module it does update as expected

#!/usr/bin/env python3
import json
import requests
from netbox_python import NetBoxClient, Result
nb = NetBoxClient(
base_url="https://netbox.domain.com/", token="<YOUR_TOKEN_HERE>"
)

def update_prefix():
prefix_id = 682
data = {"id": 682, "prefix": "192.168.71.0/25", "description": "LAB Management", "site": {"id": 279}, "tenant": {"id": 2}, "vlan": {"id": 637}}
ret = nb.ipam.prefixes.update(prefix_id, json=data)
print(f"status code: {ret.response.status_code}")
print("netbox-python module prefixes update:")
print(json.dumps(ret.data, indent=2))

url = "https://netbox.domain.com/api/ipam/prefixes/{}/".format(prefix_id)
headers = {
    "Authorization": "Token <YOUR_TOKEN_HERE>",
    "Content-Type": "application/json"
    }
data = {"id": 682, "prefix": "192.168.71.0/25", "description": "LAB Management", "site": {"id": 279}, "tenant": {"id": 2}, "vlan": {"id": 637}}
ret = requests.patch(url, json=data, headers=headers)
print(f"status code: {ret.status_code}")
print("requests module prefixes update:")
print(json.dumps(ret.json(), indent=2))

if name == "main":
update_prefix()


output below:
status code: 200
netbox-python module prefixes update:
{
"id": 682,
"url": "http://netbox.domain.com/api/ipam/prefixes/682/",
"family": {
"value": 4,
"label": "IPv4"
},
"prefix": "192.168.71.0/25",
"site": {
"id": 279,
"url": "http://netbox.domain.com/api/dcim/sites/279/",
"name": "LAB",
"slug": "lab"
},
"vrf": null,
"tenant": {
"id": 2,
"url": "http://netbox.domain.com/api/tenancy/tenants/2/",
"name": "SCA",
"slug": "sca"
},
"vlan": {
"id": 637,
"url": "http://netbox.domain.com/api/ipam/vlans/637/",
"vid": 100,
"name": "Management",
"display_name": "Management (100)"
},
"status": {
"value": "active",
"label": "Active"
},
"role": null,
"is_pool": false,
"description": "BAD BAD BAD Description",
"tags": [],
"custom_fields": {
"ActiveDirectorySite": false
},
"created": "2023-09-26",
"last_updated": "2023-09-26T13:10:43.854351Z"
}
status code: 200
requests module prefixes update:
{
"id": 682,
"url": "http://netbox.domain.com/api/ipam/prefixes/682/",
"family": {
"value": 4,
"label": "IPv4"
},
"prefix": "192.168.71.0/25",
"site": {
"id": 279,
"url": "http://netbox.domain.com/api/dcim/sites/279/",
"name": "LAB",
"slug": "lab"
},
"vrf": null,
"tenant": {
"id": 2,
"url": "http://netbox.domain.com/api/tenancy/tenants/2/",
"name": "SCA",
"slug": "sca"
},
"vlan": {
"id": 637,
"url": "http://netbox.domain.com/api/ipam/vlans/637/",
"vid": 100,
"name": "Management",
"display_name": "Management (100)"
},
"status": {
"value": "active",
"label": "Active"
},
"role": null,
"is_pool": false,
"description": "LAB Management",
"tags": [],
"custom_fields": {
"ActiveDirectorySite": false
},
"created": "2023-09-26",
"last_updated": "2023-09-26T13:10:44.357695Z"
}

insert short code snippets here

Other information:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions