Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nrnvgh opened this issue May 17, 2024 · 2 comments

Comments

@nrnvgh
Copy link
Contributor

nrnvgh commented May 17, 2024

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
Copy link
Contributor

jvanderaa commented May 17, 2024

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
Copy link
Contributor

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants