Cant delete device with cables connected to its interfaces #5001

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

Originally created by @jweiher on GitHub (Jun 15, 2021).

NetBox version

v2.11.6

Python version

3.8

Steps to Reproduce

  1. Create a device
  2. add an interface
  3. connect a cable from this interface to somewhere
  4. Try to delete that device

Expected Behavior

Either the device should be deleted or the user should get an error.

Observed Behavior

Instead a message that the device has been deleted is displayed but in fact the device stays in place.

Probably the signal that nullifies the cable is the culprit here, because it saves the interface again:
(dcim/signals.py)

@receiver(post_delete, sender=Cable)
def nullify_connected_endpoints(instance, **kwargs):
[...]
        instance.termination_a.save()
    if instance.termination_b is not None:
[...]
        instance.termination_b.save()

Which also leads to postgres not being happy at all:

2021-06-15 18:06:54.055 CEST [5083] STATEMENT:  COMMIT
2021-06-15 18:09:20.723 CEST [4807] ERROR:  insert or update on table "dcim_interface" violates foreign key constraint "dcim_interface_device_id_359c6115_fk"
2021-06-15 18:09:20.723 CEST [4807] DETAIL:  Key (device_id)=(6843) is not present in table "dcim_device".

Also an interface with cables attached cant be deleted and creates the same behavior (message says it has been deleted, but it isnt). If this is the expected behavior the user should get an error about it or it should be implicitly deleted (like ips).

regards
Jan

Originally created by @jweiher on GitHub (Jun 15, 2021). ### NetBox version v2.11.6 ### Python version 3.8 ### Steps to Reproduce 1. Create a device 2. add an interface 3. connect a cable from this interface to somewhere 4. Try to delete that device ### Expected Behavior Either the device should be deleted or the user should get an error. ### Observed Behavior Instead a message that the device has been deleted is displayed but in fact the device stays in place. Probably the signal that nullifies the cable is the culprit here, because it saves the interface again: (dcim/signals.py) ``` @receiver(post_delete, sender=Cable) def nullify_connected_endpoints(instance, **kwargs): [...] instance.termination_a.save() if instance.termination_b is not None: [...] instance.termination_b.save() ``` Which also leads to postgres not being happy at all: ``` 2021-06-15 18:06:54.055 CEST [5083] STATEMENT: COMMIT 2021-06-15 18:09:20.723 CEST [4807] ERROR: insert or update on table "dcim_interface" violates foreign key constraint "dcim_interface_device_id_359c6115_fk" 2021-06-15 18:09:20.723 CEST [4807] DETAIL: Key (device_id)=(6843) is not present in table "dcim_device". ``` Also an interface with cables attached cant be deleted and creates the same behavior (message says it has been deleted, but it isnt). If this is the expected behavior the user should get an error about it or it should be implicitly deleted (like ips). regards Jan
adam added the type: bug label 2025-12-29 19:23:02 +01:00
adam closed this issue 2025-12-29 19:23:03 +01:00
Author
Owner

@jweiher commented on GitHub (Jun 15, 2021):

Will close it, its fixed in #6602

@jweiher commented on GitHub (Jun 15, 2021): Will close it, its fixed in #6602
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5001