netboxlabs / netbox-branching

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

Constraint violations raised when merging a branch cannot be resolved by deleting the offending object #32

Open jeremystretch opened 3 months ago

jeremystretch commented 3 months ago

Plugin Version

v0.2.0

NetBox Version

v4.1-beta1

Python Version

3.10

Steps to Reproduce

  1. Create two branches, A and B
  2. In both branches, create a new interface named "eth0" on a device
  3. Merge branch A
  4. Attempt to merge branch B. An IntegrityError is raised, complaining that the name of the interface being created is not unique to the device (which is expected).
  5. Delete the interface from branch B.
  6. Attempt to merge branch B again.

Expected Behavior

The merge should be successful, as the offending object has been deleted.

Observed Behavior

The same exception continues to be raised, because the branch's history is being replayed in chronological order:

  1. The interface with the offending name is created.
  2. The interface is deleted.

We should be able to work around this by deferring constraint checks until the end of the transaction.

jeremystretch commented 2 months ago

We should be able to work around this by deferring constraint checks until the end of the transaction.

This approach may not be tenable, as it would require altering all existing unique constraints in NetBox to be deferrable. In addition to the complexity of such an undertaking, the use of deferrable constraints might also result in reduced performance for certain queries.