netboxlabs / netbox-branching

Official NetBox Labs plugin that implements git-like branching functionality for NetBox
http://netboxlabs.com
Other
61 stars 1 forks source link

Exception and invalid CablePath state after editing a cable in a branch #98

Closed Supermathie closed 1 month ago

Supermathie commented 1 month ago

Plugin Version

0.4.0

NetBox Version

4.1.0

Python Version

3.12

Steps to Reproduce

I'm using the netbox-community docker image.

Create a new admin with python manage.py createsuperuser Provision a new Site: site Create a new Device Role: test Create a new Manufacturer: Arista Load Device Type from devicetype-library: AWE-5310.yaml Create 4 Devices: router0[1-4] Create connection from router01 Ethernet1/1 to router02 Ethernet1/1 Create connection from router01 Ethernet1/2 to router02 Ethernet1/2

image

Check Cable #1 trace

image

Create branch: test Switch to branch: test Edit Cable #1, switch B side to router03 Ethernet1/1

image

Expected Behavior

The edit should complete normally without affecting the Main branch.

Observed Behavior

Switch to branch: 'Main'

image

Note Cable #1 connection has been affected by the branch edit.

Check Cable #1 trace

image

Supermathie commented 1 month ago

FYI this is on a test instance (copy of production data) so I am free to try different things and can reproduce from a data dump I have.

jeremystretch commented 1 month ago

@Supermathie please edit your initial post above to provide exact, step-by-step instructions for reproducing the error. Screenshots are not sufficient. You'll also need to reproduce the issue with a clean v4.1.0 database, as we cannot address potential issues with the original data.

Supermathie commented 1 month ago

OK, done.

jeremystretch commented 1 month ago

This appears to be a bug in the save() method of the Cable model. Calls to save() and delete() within that method do not respect the active connection and need to be corrected.

VintageCake commented 1 month ago

This appears to still be busted in the 0.5.0 version with netbox 4.1.1. I assume it is related but merging the branch makes the issues persist in the main branch until the cable is updated by moving it from one interface to another.

jeremystretch commented 1 month ago

Dug into this a bit further and I was mistaken in my analysis above: We've actually neglected to copy the cable paths table during branch provisioning, so all queries and mutations of cable paths are affecting the main schema.

The good news is that this should be a fairly easy fix. :crossed_fingers:

jeremystretch commented 1 month ago

I have a branch with the immediate fix (provisioning the dcim_cablepath table for a branch), however I still need to identify a solution for ensuring the cable paths get recalculated on merge.

jeremystretch commented 1 month ago

I've submitted PR #149 to address the primary issue raised here: Modifying a cable connection within a branch impacts the main schema.

I've also submitted a separate bug report (#150) to capture the secondary issue raised here, which is the incomplete cable paths resulting from a branch merge.