Changing a site's region does not change the circuit or circuit-termination region #11509

Closed
opened 2025-12-29 21:46:12 +01:00 by adam · 10 comments
Owner

Originally created by @rfdrake on GitHub (Aug 20, 2025).

Originally assigned to: @DanSheps on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.3.6

Python Version

3.12

Steps to Reproduce

  1. Edit a site and change it's region from one place to another
  2. Check and see that circuits and circuit-terminations are still showing for that site in the old region

I have tested this on my local instance and on the demo instance. Both with a GUI move and a pynetbox move. Afterwords, I tried a manage.py reindex, restarting netbox, and various other commands to see if I could force it to update.

Finally I tried writing this script to change the region on all the circuits. It didn't work.

region_name = 'Old region'
for circuit in nb.circuits.circuits.filter(region=slugify(region_name)):
        for side in [ circuit.termination_a, circuit.termination_z ]:
           if side and re.search(r'/sites/', side.termination.url):
                term = nb.circuits.circuit_terminations.get(id=side.id)
                site = nb.dcim.sites.get(id=side.termination_id)
                print(f"Moving {circuit} from {region_name} to {site.region}")
                term.region = site.region
                term.save()
                circuit.region = site.region
                circuit.save()

But, as a workaround, this does work:

region_name = 'Old region'
for circuit in nb.circuits.circuits.filter(region=slugify(region_name)):
        for side in [ circuit.termination_a, circuit.termination_z ]:
           if side and re.search(r'/sites/', side.termination.url):
                term = nb.circuits.circuit_terminations.get(id=side.id)
                old_desc = term.description
                term.description = 'z'
                term.save()
                term.description = old_desc
                term.save()    

Expected Behavior

Circuits and circuit terminations should update when the site updates. I recognize this is super rare for most people. Even I don't move sites around much, but sometimes I need to expand the hierarchy to add something more specific, like if a site is tagged as "USA" and we decide to put it in "DC" because that is where it actually is.

Observed Behavior

Circuits just won't move regions.

Originally created by @rfdrake on GitHub (Aug 20, 2025). Originally assigned to: @DanSheps on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.3.6 ### Python Version 3.12 ### Steps to Reproduce 1. Edit a site and change it's region from one place to another 2. Check and see that circuits and circuit-terminations are still showing for that site in the old region I have tested this on my local instance and on the demo instance. Both with a GUI move and a pynetbox move. Afterwords, I tried a manage.py reindex, restarting netbox, and various other commands to see if I could force it to update. Finally I tried writing this script to change the region on all the circuits. It didn't work. ``` region_name = 'Old region' for circuit in nb.circuits.circuits.filter(region=slugify(region_name)): for side in [ circuit.termination_a, circuit.termination_z ]: if side and re.search(r'/sites/', side.termination.url): term = nb.circuits.circuit_terminations.get(id=side.id) site = nb.dcim.sites.get(id=side.termination_id) print(f"Moving {circuit} from {region_name} to {site.region}") term.region = site.region term.save() circuit.region = site.region circuit.save() ``` But, as a workaround, this does work: ``` region_name = 'Old region' for circuit in nb.circuits.circuits.filter(region=slugify(region_name)): for side in [ circuit.termination_a, circuit.termination_z ]: if side and re.search(r'/sites/', side.termination.url): term = nb.circuits.circuit_terminations.get(id=side.id) old_desc = term.description term.description = 'z' term.save() term.description = old_desc term.save() ``` ### Expected Behavior Circuits and circuit terminations should update when the site updates. I recognize this is super rare for most people. Even I don't move sites around much, but sometimes I need to expand the hierarchy to add something more specific, like if a site is tagged as "USA" and we decide to put it in "DC" because that is where it actually is. ### Observed Behavior Circuits just won't move regions.
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:46:12 +01:00
adam closed this issue 2025-12-29 21:46:13 +01:00
Author
Owner

@arthanson commented on GitHub (Aug 21, 2025):

Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.

@arthanson commented on GitHub (Aug 21, 2025): Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include **detailed steps** that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.
Author
Owner

@rfdrake commented on GitHub (Aug 21, 2025):

Change a region in a site:

Image Image

You can see here that after this is done there are still circuits represented by the group Connecticut:
Image

Those circuits are the ones for the DM-Stamford site:
Image

@rfdrake commented on GitHub (Aug 21, 2025): Change a region in a site: <img width="702" height="298" alt="Image" src="https://github.com/user-attachments/assets/9f816b14-4127-475e-9194-c8264464995d" /> <img width="786" height="305" alt="Image" src="https://github.com/user-attachments/assets/114313ee-e891-4ea4-8ba8-f25d536fb04f" /> You can see here that after this is done there are still circuits represented by the group Connecticut: <img width="1578" height="313" alt="Image" src="https://github.com/user-attachments/assets/d327ed12-e01e-4153-ad08-3b1ead51710c" /> Those circuits are the ones for the DM-Stamford site: <img width="1588" height="218" alt="Image" src="https://github.com/user-attachments/assets/c671aa9a-2f3a-4c30-b8ae-4a110eea8382" />
Author
Owner

@arthanson commented on GitHub (Aug 21, 2025):

@rfdrake Thanks for the response, but you are showing the results of what you are doing not the detailed steps to reproduce it, like:

  1. create region "region1"
  2. create region "region2"
  3. create site "site1" in "region1"
  4. ...

I did try to reproduce this with a circuit on my environment that had a termination in site "DM-Akron" which was in region Ohio, then changed it to be "MDF" which is in "North Carolina" and then looked at the circuit count in Related objects and it had updated correctly (in my case changed from a 2 to a 1), so I am not able to currently reproduce it.

However, without the detailed reproduction steps I have no idea if I am doing the same things you are to reproduce the issue. For example in your original bug report you state it is showing for that site in the old region, you never mentioned it was in related objects. This makes it difficult for us as we have to make a lot of guesses and assumptions on how to reproduce an issue without detailed (step by step) reproduction steps.

There can also be edge cases, for example regions and sites are hierarchical - you might be using a nested region and when I try I use a non-nested region and it doesn't show (note: I was using nested regions when I tried to reproduce). Again, without detailed reproduction steps we may be trying two different things.

@arthanson commented on GitHub (Aug 21, 2025): @rfdrake Thanks for the response, but you are showing the results of what you are doing not the detailed steps to reproduce it, like: 1. create region "region1" 2. create region "region2" 3. create site "site1" in "region1" 4. ... I did try to reproduce this with a circuit on my environment that had a termination in site "DM-Akron" which was in region Ohio, then changed it to be "MDF" which is in "North Carolina" and then looked at the circuit count in Related objects and it had updated correctly (in my case changed from a 2 to a 1), so I am not able to currently reproduce it. However, without the detailed reproduction steps I have no idea if I am doing the same things you are to reproduce the issue. For example in your original bug report you state it is showing for that site in the old region, you never mentioned it was in related objects. This makes it difficult for us as we have to make a lot of guesses and assumptions on how to reproduce an issue without detailed (step by step) reproduction steps. There can also be edge cases, for example regions and sites are hierarchical - you might be using a nested region and when I try I use a non-nested region and it doesn't show (note: I was using nested regions when I tried to reproduce). Again, without detailed reproduction steps we may be trying two different things.
Author
Owner

@rfdrake commented on GitHub (Aug 21, 2025):

The screenshots above were made in the netbox beta-demo instance here: https://beta-demo.netbox.dev/dcim/regions/49/

I think one thing that might be different in our test cases is I was changing the region of the site, not the circuit termination itself. So in the demo instance, I moved "DM-Stanford" from Connecticut to Kentucky.

I'm starting up a new instance now and I'll try to add just enough objects to simulate the problem. If i can do so I'll send you the exact commands needed to break it the same way.

Thanks,
Robert

@rfdrake commented on GitHub (Aug 21, 2025): The screenshots above were made in the netbox beta-demo instance here: https://beta-demo.netbox.dev/dcim/regions/49/ I think one thing that might be different in our test cases is I was changing the region of the site, not the circuit termination itself. So in the demo instance, I moved "DM-Stanford" from Connecticut to Kentucky. I'm starting up a new instance now and I'll try to add just enough objects to simulate the problem. If i can do so I'll send you the exact commands needed to break it the same way. Thanks, Robert
Author
Owner

@rfdrake commented on GitHub (Aug 22, 2025):

On an empty database, this script will cause the issue. The only thing I did before applying the script was to set a superuser, login and give them a token.

#!/usr/bin/env python3

import sys
import re
import pynetbox
import os
import urllib3
from slugify import slugify

nb = pynetbox.api(url=os.environ["NETBOX_URL"], token=os.environ["NETBOX_TOKEN"])

# add new regions
states = ["AL", "AK"]
for state in states:
    r = nb.dcim.regions.get(name=state) or nb.dcim.regions.create(name=state, slug=slugify(state))
    r.save()

region_id = nb.dcim.regions.get(name="AL").id
site = nb.dcim.sites.get(name="Site1") or nb.dcim.sites.create(
    name="Site1", region=region_id, slug="site1"
)
site.save()
site.update({"region": region_id})

provider = nb.circuits.providers.get(name="TestProvider") or nb.circuits.providers.create(
    name="TestProvider", slug="testprovider"
)
provider.save()
circuit_type = nb.circuits.circuit_types.get(
    name="TestCircuitType"
) or nb.circuits.circuit_types.create(name="TestCircuitType", slug="testcircuittype")
circuit_type.save()
circuit = nb.circuits.circuits.get(cid="1111") or nb.circuits.circuits.create(
    provider=provider.id, type=circuit_type.id, cid="1111", status="active"
)
circuit.save()

term_a = nb.circuits.circuit_terminations.get(
    circuit=circuit.id, term_side="A"
) or nb.circuits.circuit_terminations.create(
    circuit=circuit.id, term_side="A", termination_type="dcim.site", termination_id=site.id
)
term_a.save()

region_id = nb.dcim.regions.get(name="AK")
site.update({"region": region_id})

Once this is applied, if you look at the AL region it will show the circuit and circuit termination object.

Here is my pip list for installed module versions:

Package            Version
------------------ --------
attrs              25.3.0
black              25.1.0
cattrs             25.1.1
certifi            2025.8.3
charset-normalizer 3.4.3
click              8.2.1
idna               3.10
macaddress         2.0.2
mypy_extensions    1.1.0
packaging          25.0
pathspec           0.12.1
pip                24.3.1
platformdirs       4.3.8
pynetbox           7.5.0
python-slugify     8.0.4
requests           2.32.5
requests-cache     1.2.1
text-unidecode     1.3
typing_extensions  4.14.1
url-normalize      2.2.1
urllib3            2.5.0
@rfdrake commented on GitHub (Aug 22, 2025): On an empty database, this script will cause the issue. The only thing I did before applying the script was to set a superuser, login and give them a token. ``` #!/usr/bin/env python3 import sys import re import pynetbox import os import urllib3 from slugify import slugify nb = pynetbox.api(url=os.environ["NETBOX_URL"], token=os.environ["NETBOX_TOKEN"]) # add new regions states = ["AL", "AK"] for state in states: r = nb.dcim.regions.get(name=state) or nb.dcim.regions.create(name=state, slug=slugify(state)) r.save() region_id = nb.dcim.regions.get(name="AL").id site = nb.dcim.sites.get(name="Site1") or nb.dcim.sites.create( name="Site1", region=region_id, slug="site1" ) site.save() site.update({"region": region_id}) provider = nb.circuits.providers.get(name="TestProvider") or nb.circuits.providers.create( name="TestProvider", slug="testprovider" ) provider.save() circuit_type = nb.circuits.circuit_types.get( name="TestCircuitType" ) or nb.circuits.circuit_types.create(name="TestCircuitType", slug="testcircuittype") circuit_type.save() circuit = nb.circuits.circuits.get(cid="1111") or nb.circuits.circuits.create( provider=provider.id, type=circuit_type.id, cid="1111", status="active" ) circuit.save() term_a = nb.circuits.circuit_terminations.get( circuit=circuit.id, term_side="A" ) or nb.circuits.circuit_terminations.create( circuit=circuit.id, term_side="A", termination_type="dcim.site", termination_id=site.id ) term_a.save() region_id = nb.dcim.regions.get(name="AK") site.update({"region": region_id}) ``` Once this is applied, if you look at the AL region it will show the circuit and circuit termination object. Here is my pip list for installed module versions: ``` Package Version ------------------ -------- attrs 25.3.0 black 25.1.0 cattrs 25.1.1 certifi 2025.8.3 charset-normalizer 3.4.3 click 8.2.1 idna 3.10 macaddress 2.0.2 mypy_extensions 1.1.0 packaging 25.0 pathspec 0.12.1 pip 24.3.1 platformdirs 4.3.8 pynetbox 7.5.0 python-slugify 8.0.4 requests 2.32.5 requests-cache 1.2.1 text-unidecode 1.3 typing_extensions 4.14.1 url-normalize 2.2.1 urllib3 2.5.0 ```
Author
Owner

@github-actions[bot] commented on GitHub (Aug 30, 2025):

This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.

@github-actions[bot] commented on GitHub (Aug 30, 2025): This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.
Author
Owner

@rfdrake commented on GitHub (Aug 31, 2025):

I'm not sure what else I can add to the report. I wish I knew the cause and could offer a suggested fix, but I'm just not familiar with the deep workings of netbox.

@rfdrake commented on GitHub (Aug 31, 2025): I'm not sure what else I can add to the report. I wish I knew the cause and could offer a suggested fix, but I'm just not familiar with the deep workings of netbox.
Author
Owner

@DanSheps commented on GitHub (Oct 5, 2025):

Demornalized field wasn't registered.

Also found a few corner cases we might want to evaluate too.

@DanSheps commented on GitHub (Oct 5, 2025): Demornalized field wasn't registered. Also found a few corner cases we might want to evaluate too.
Author
Owner

@jnovinger commented on GitHub (Oct 6, 2025):

@DanSheps , would definitely be interested in hearing those corner cases, unless you plan on opening an issue for them.

@jnovinger commented on GitHub (Oct 6, 2025): @DanSheps , would definitely be interested in hearing those corner cases, unless you plan on opening an issue for them.
Author
Owner

@jnovinger commented on GitHub (Oct 6, 2025):

Fixed in #20503.

@jnovinger commented on GitHub (Oct 6, 2025): Fixed in #20503.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11509