netbox-community / pynetbox

Python API client library for Netbox.
Apache License 2.0
543 stars 167 forks source link

Pynetbox 7 fails to create circuit with Netbox 3.5. due to provider_account required #550

Closed dmulyalin closed 1 year ago

dmulyalin commented 1 year ago

Run into this issue while was trying to create circuit in Netbox 3.5:

[2023-05-02 12:17:55,097] /tmp/pytest/netbox_data.py:1374 INFO - creating curcuits
[2023-05-02 12:17:55,097] /tmp/pytest/netbox_data.py:1381 INFO - Creating circuit: {'provider': {'slug': 'provider1'}, 'type': {'slug': 'darkfibre'}, 'status': 'active', 'cid': 'CID1'}
[2023-05-02 12:17:55,108] /usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:452 DEBUG - http://192.168.75.129:8000 "POST /api/circuits/circuits/ HTTP/1.1" 400 48
[2023-05-02 12:17:55,108] /tmp/pytest/netbox_data.py:1402 ERROR - creating circuit '{'provider': {'slug': 'provider1'}, 'type': {'slug': 'darkfibre'}, 'status': 'active', 'cid': 'CID1'}' error 'The request failed with code 400 Bad Request: {'provider_account': ['This field is required.']}'
Traceback (most recent call last):
  File "/tmp/pytest/netbox_data.py", line 1382, in create_circuits
    circuit = nb.circuits.circuits.create(**item)
  File "/usr/local/lib/python3.9/site-packages/pynetbox/core/endpoint.py", line 313, in create
    req = Request(
  File "/usr/local/lib/python3.9/site-packages/pynetbox/core/query.py", line 396, in post
    return self._make_call(verb="post", data=data)
  File "/usr/local/lib/python3.9/site-packages/pynetbox/core/query.py", line 284, in _make_call
    raise RequestError(req)
pynetbox.core.query.RequestError: The request failed with code 400 Bad Request: {'provider_account': ['This field is required.']}
root@salt-master:/tmp/pytest# pip list | grep netbox
pynetbox             7.0.0
root@salt-master:/tmp/pytest# 

Not sure if it is a Pynetbox or Netbox itself issue and whether this is expected at all but Netbox API states that provider_account field is not mandatory: image

Code to reproduce:

circuits = [
    {
        "provider": {"slug": slugify("Provider1")},
        "type": {"slug": slugify("DarkFibre")},
        "status": "active",
        "cid": "CID1"
    }
]
for item in circuits:
    circuit = nb.circuits.circuits.create(**item)
dmulyalin commented 1 year ago

I believe this one fixed under - https://github.com/netbox-community/netbox/issues/12396