API - not possible to change a circuit-termination from a "site" to a "provider network" or back again #5474

Closed
opened 2025-12-29 19:28:28 +01:00 by adam · 2 comments
Owner

Originally created by @s2156945 on GitHub (Oct 6, 2021).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.0.5

Python version

3.9

Steps to Reproduce

Steps:

  1. Create or have existing a circuit termination which is associated with a site
  2. Using the API try to change to a provider_network type termination by clearing the site and setting the provider_network:
    PATCH /api/circuits/circuit-terminations/55/
    { "provider_network" : 3, "site" : null }

The reverse is also tried (swap site and provider network in the above steps)

Code to reproduce both directions against the demo - first need to add bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as a token at https://demo.netbox.dev/admin/users/token/add/

`import pynetbox
import logging
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

assumed sites and providers as per the demo instance

nb = pynetbox.api(
'https://demo.netbox.dev',
token='bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
)

create a circuit

circuit = nb.circuits.circuits.create({"cid": "Bug Report Circuit", "provider": {"slug":"level-3"}, "type": {"slug": "mpls"}})

add termination a at a site

ct_a = nb.circuits.circuit_terminations.create({"circuit": circuit['id'], "term_side": "A", "site": 1})

add termination z through a provider network

ct_z = nb.circuits.circuit_terminations.create({"circuit": circuit['id'], "term_side": "Z", "provider_network": 1})

try and switch them around

try:
ct_a.update({"site": None, "provider_network": 1})
except Exception as e:
print (f"Error changing from site to provider_network: {e}")

try:
ct_z.update({"site": 1, "provider_network": None})
except Exception as e:
print (f"Error changing from provider_network to site : {e}")
Result:
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): demo.netbox.dev:443
DEBUG:urllib3.connectionpool:https://demo.netbox.dev:443 "POST /api/circuits/circuits/ HTTP/1.1" 201 648
DEBUG:urllib3.connectionpool:https://demo.netbox.dev:443 "POST /api/circuits/circuit-terminations/ HTTP/1.1" 201 588
DEBUG:urllib3.connectionpool:https://demo.netbox.dev:443 "POST /api/circuits/circuit-terminations/ HTTP/1.1" 201 603
DEBUG:urllib3.connectionpool:https://demo.netbox.dev:443 "PATCH /api/circuits/circuit-terminations/55/ HTTP/1.1" 400 40
Error changing from site to provider_network: The request failed with code 400 Bad Request: {'site': ['This field may not be null.']}
DEBUG:urllib3.connectionpool:https://demo.netbox.dev:443 "PATCH /api/circuits/circuit-terminations/56/ HTTP/1.1" 400 52
Error changing from provider_network to site : The request failed with code 400 Bad Request: {'provider_network': ['This field may not be null.']}
`

Expected Behavior

The circuit termination should have a provider network and no site.

(in the reverse case the circuit termination should have a site and no provider network)

The API ideally would prevent a circuit termination from having both (or neither) with a relevant error message.

Observed Behavior

The circuit termination now has both a site and a provider_network, which is not sensible and possible in the web UI.

Work-around:

  • delete the circuit termination and add it with the correct details
Originally created by @s2156945 on GitHub (Oct 6, 2021). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.0.5 ### Python version 3.9 ### Steps to Reproduce Steps: 1. Create or have existing a circuit termination which is associated with a site 2. Using the API try to change to a provider_network type termination by clearing the site and setting the provider_network: `PATCH /api/circuits/circuit-terminations/55/` `{ "provider_network" : 3, "site" : null }` The reverse is also tried (swap site and provider network in the above steps) Code to reproduce both directions against the demo - first need to add bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as a token at https://demo.netbox.dev/admin/users/token/add/ `import pynetbox import logging logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG) requests_log = logging.getLogger("requests.packages.urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True # assumed sites and providers as per the demo instance nb = pynetbox.api( 'https://demo.netbox.dev', token='bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' ) # create a circuit circuit = nb.circuits.circuits.create({"cid": "Bug Report Circuit", "provider": {"slug":"level-3"}, "type": {"slug": "mpls"}}) # add termination a at a site ct_a = nb.circuits.circuit_terminations.create({"circuit": circuit['id'], "term_side": "A", "site": 1}) # add termination z through a provider network ct_z = nb.circuits.circuit_terminations.create({"circuit": circuit['id'], "term_side": "Z", "provider_network": 1}) # try and switch them around try: ct_a.update({"site": None, "provider_network": 1}) except Exception as e: print (f"Error changing from site to provider_network: {e}") try: ct_z.update({"site": 1, "provider_network": None}) except Exception as e: print (f"Error changing from provider_network to site : {e}") ` Result: ` DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): demo.netbox.dev:443 DEBUG:urllib3.connectionpool:https://demo.netbox.dev:443 "POST /api/circuits/circuits/ HTTP/1.1" 201 648 DEBUG:urllib3.connectionpool:https://demo.netbox.dev:443 "POST /api/circuits/circuit-terminations/ HTTP/1.1" 201 588 DEBUG:urllib3.connectionpool:https://demo.netbox.dev:443 "POST /api/circuits/circuit-terminations/ HTTP/1.1" 201 603 DEBUG:urllib3.connectionpool:https://demo.netbox.dev:443 "PATCH /api/circuits/circuit-terminations/55/ HTTP/1.1" 400 40 Error changing from site to provider_network: The request failed with code 400 Bad Request: {'site': ['This field may not be null.']} DEBUG:urllib3.connectionpool:https://demo.netbox.dev:443 "PATCH /api/circuits/circuit-terminations/56/ HTTP/1.1" 400 52 Error changing from provider_network to site : The request failed with code 400 Bad Request: {'provider_network': ['This field may not be null.']} ` ### Expected Behavior The circuit termination should have a provider network and no site. (in the reverse case the circuit termination should have a site and no provider network) The API ideally would prevent a circuit termination from having both (or neither) with a relevant error message. ### Observed Behavior The circuit termination now has both a site and a provider_network, which is not sensible and possible in the web UI. Work-around: - delete the circuit termination and add it with the correct details
adam added the type: bugstatus: accepted labels 2025-12-29 19:28:28 +01:00
adam closed this issue 2025-12-29 19:28:28 +01:00
Author
Owner

@jeremystretch commented on GitHub (Oct 6, 2021):

Thanks for the detailed report. For the future, really all we'd need in this case is the raw API request and the error message; no need to test with pynetbox as well. Should be an easy fix though.

@jeremystretch commented on GitHub (Oct 6, 2021): Thanks for the detailed report. For the future, really all we'd need in this case is the raw API request and the error message; no need to test with pynetbox as well. Should be an easy fix though.
Author
Owner

@s2156945 commented on GitHub (Oct 7, 2021):

@jeremystretch thanks! I'm newish at python (perl guy) so I had to make sure I wasn't doing anything dumb - I find that when I write a good test case I find that I am the problem at least half the time :-) Also I had to test against the latest netbox which is super easy with your demo server.

@s2156945 commented on GitHub (Oct 7, 2021): @jeremystretch thanks! I'm newish at python (perl guy) so I had to make sure I wasn't doing anything dumb - I find that when I write a good test case I find that I am the problem at least half the time :-) Also I had to test against the latest netbox which is super easy with your demo server.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5474