nautobot / pynautobot

Nautobot Python SDK
https://pynautobot.readthedocs.io/en/latest/index.html
Apache License 2.0
33 stars 29 forks source link

Bug: calling the `create()` method on `prefix.available_ips()` fails with an exception #194

Open nrnvgh opened 1 month ago

nrnvgh commented 1 month ago

Environment

pynautobot: 1.5.2 nautobot: 1.6.21 client-side python: 3.11.8

Details

Using the example in the pynautobot docs as a starting point: Code:

from pprint import pprint
from pynautobot.api import Nautobot

nc = Nautobot({args})
nb_prefix = nc.ipam.prefixes.get(prefix="10.0.10.0/31")
pprint(nb_prefix.available_ips.list())
print("\n")

nb_prefix.available_ips.create([{} for _ in range(2)])

Execution result:

[<pynautobot.models.ipam.IpAddresses ('10.0.10.0/31') at 0x1059d0290>,
 <pynautobot.models.ipam.IpAddresses ('10.0.10.1/31') at 0x1046ba9d0>]

pynautobot.core.query.RequestError: The request failed with code 400 Bad Request: [{'status': ['This field is required.']}, {'status': ['This field is required.']}]
jvanderaa commented 1 month ago

Testing code

# Import pynautobot
import pynautobot

# Connect to the Nautobot SDK
nb = pynautobot.api(url="https://demo.nautobot.com", token="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")

prefix = nb.ipam.prefixes.get(prefix="10.0.192.0/18")

I tried to stuff the status required into the data of the create() endpoint, but that failed, generating the following error:

(Pdb) prefix.available_ips.create(data={"status": "Active"})
*** pynautobot.core.query.RequestError: The request failed with code 500 Internal Server Error: {'error': 'duplicate key value violates unique constraint "ipam_ipaddress_parent_id_host_89330d7e_uniq"\nDETAIL:  Key (parent_id, host)=(85449467-4eae-4df0-a4df-eab7fdab4ed9, \\x0a00c001) already exists.\n', 'exception': 'IntegrityError', 'nautobot_version': '2.2.4', 'python_version': '3.11.9'}
jvanderaa commented 1 month ago

I then set x to be the first IP Address:

(Pdb) x = prefix.available_ips.list()
(Pdb) x[0]
<pynautobot.models.ipam.IpAddresses ('10.0.192.1/18') at 0x103bdebd0>
(Pdb) x[0].address
'10.0.192.1/18'