Posted circuit terminations not appearing in circuit detail view #5558

Closed
opened 2025-12-29 19:29:23 +01:00 by adam · 1 comment
Owner

Originally created by @ghost on GitHub (Oct 26, 2021).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.0.8

Python version

3.9

Steps to Reproduce

Start fresh netbox instance.
Populate netbox db with testdata: (create all attrbutes with only the required fields.)

  • Create a Provider
  • Create a Site
  • Create a Circuit Type
  • Create a Circuit (with the provider and circuit type just created)
  • Create a Provider Network
  • Create a token from the admin dashboard. (I put this in .env file under variable NETBOX_TOKEN)

Since this is a fresh NetBox instance all ids should start on id: int = 1.

By using requests we post termination Z & A to the newly created circuit:

from decouple import config
import requests
import json


headers = {
    'Authorization': f'Token {config("NETBOX_TOKEN")}',
    'Content-Type': 'application/json',
    "Accept": "application/json; indent=4"
}

data = [
{'circuit': 1, 'site': 1, 'term_side': 'A'}, 
{'circuit': 1, 'provider_network': 1, 'term_side': 'Z'}
]

response = requests.post(
  f'{netbox_env}/api/circuits/circuit-terminations/', 
  headers=headers,
  data=json.dumps(data)
  )
# output is indeed a 201 response.

Expected Behavior

Both circuit termination points (A & Z) to be linked to the circuit with id: 1, and appearing in the circuit view under: /circuits/circuits/1/.

Observed Behavior

Both circuit terminations are indeed in the /api/circuits/circuit-terminations/ endpoint. However, if we go to: /circuits/circuits/1/, only the termination Z side appears. Picture to illustrate:
image

If I also visit the terminal checking this specific circuit instance (id:1) I found that there is no termination_a_side. ref: (terminal screen shot)
image

Finally, the posted data is tested being posted as singles. This also works fine.

Thank you for taking the time to read this!

Originally created by @ghost on GitHub (Oct 26, 2021). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.0.8 ### Python version 3.9 ### Steps to Reproduce Start fresh netbox instance. Populate netbox db with testdata: (create all attrbutes with only the required fields.) - Create a `Provider` - Create a `Site` - Create a `Circuit Type` - Create a `Circuit` (with the provider and circuit type just created) - Create a `Provider Network` - Create a token from the admin dashboard. (I put this in `.env` file under variable `NETBOX_TOKEN`) Since this is a fresh NetBox instance all ids should start on `id: int = 1`. By using `requests` we post termination Z & A to the newly created circuit: ```python from decouple import config import requests import json headers = { 'Authorization': f'Token {config("NETBOX_TOKEN")}', 'Content-Type': 'application/json', "Accept": "application/json; indent=4" } data = [ {'circuit': 1, 'site': 1, 'term_side': 'A'}, {'circuit': 1, 'provider_network': 1, 'term_side': 'Z'} ] response = requests.post( f'{netbox_env}/api/circuits/circuit-terminations/', headers=headers, data=json.dumps(data) ) # output is indeed a 201 response. ``` ### Expected Behavior Both circuit termination points (A & Z) to be linked to the circuit with id: `1`, and appearing in the circuit view under: `/circuits/circuits/1/`. ### Observed Behavior Both circuit terminations are indeed in the `/api/circuits/circuit-terminations/` endpoint. However, if we go to: `/circuits/circuits/1/`, only the termination Z side appears. Picture to illustrate: ![image](https://user-images.githubusercontent.com/83281583/138927784-b66faed0-497e-4971-80f0-602909600096.png) If I also visit the terminal checking this specific circuit instance (id:`1`) I found that there is no `termination_a_side`. ref: (terminal screen shot) ![image](https://user-images.githubusercontent.com/83281583/138928722-815fdc4d-0c2a-4366-b8ff-7b070432aaa4.png) Finally, the posted data is tested being posted as singles. This also works fine. Thank you for taking the time to read this!
adam added the type: bugstatus: accepted labels 2025-12-29 19:29:23 +01:00
adam closed this issue 2025-12-29 19:29:23 +01:00
Author
Owner

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

@PerAStad thank you for the thorough bug report!

When a circuit termination gets created, the relevant foreign key (termination_a or termination_b) gets updated on its parent circuit. But because we're creating two terminations at once, using two "copies" of the parent circuit, we're saving it twice. The first time, termination_a is set to the ID of the new CircuitTermination, and termination_b is null. The second time, termination_a is null and termination_b is set, which is how we end up in this state.

Seems like an easy fix though: We just need to call refresh_from_db() on the parent circuit instance prior to each save, to ensure that we're working with the most recent copy.

@jeremystretch commented on GitHub (Oct 27, 2021): @PerAStad thank you for the thorough bug report! When a circuit termination gets created, the relevant foreign key (`termination_a` or `termination_b`) gets updated on its parent circuit. But because we're creating two terminations at once, using two "copies" of the parent circuit, we're saving it twice. The first time, `termination_a` is set to the ID of the new CircuitTermination, and `termination_b` is null. The second time, `termination_a` is null and `termination_b` is set, which is how we end up in this state. Seems like an easy fix though: We just need to call `refresh_from_db()` on the parent circuit instance prior to each save, to ensure that we're working with the most recent copy.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5558