Interface.DoesNotExist error when deleting a device with active connections #2922

Closed
opened 2025-12-29 18:23:27 +01:00 by adam · 14 comments
Owner

Originally created by @dgarros on GitHub (Oct 1, 2019).

Environment

  • Python version: 3.6.8
  • NetBox version: 2.6.5

When deleting a device that has one or multiple connections to other devices, netbox is returning an dcim.models.Interface.DoesNotExist error.
If I disconnect all interfaces prior to deleting the device, the error is not present.

<class 'dcim.models.Interface.DoesNotExist'>

Interface matching query does not exist

Steps to Reproduce

  1. Create 2 devices (dev1 and dev2)
  2. Connect 2 interfaces together from dev1 and dev2
  3. Delete dev1

Expected Behavior

Device should be deleted without issue and all connections to this device should be deleted as well

Observed Behavior

Netbox is returning a dcim.models.Interface.DoesNotExist error

<class 'dcim.models.Interface.DoesNotExist'>
Interface matching query does not exist
Originally created by @dgarros on GitHub (Oct 1, 2019). ### Environment * Python version: 3.6.8 * NetBox version: 2.6.5 When deleting a device that has one or multiple connections to other devices, netbox is returning an `dcim.models.Interface.DoesNotExist` error. If I disconnect all interfaces prior to deleting the device, the error is not present. ``` <class 'dcim.models.Interface.DoesNotExist'> Interface matching query does not exist ``` ### Steps to Reproduce 1. Create 2 devices (dev1 and dev2) 2. Connect 2 interfaces together from dev1 and dev2 3. Delete dev1 ### Expected Behavior Device should be deleted without issue and all connections to this device should be deleted as well ### Observed Behavior Netbox is returning a `dcim.models.Interface.DoesNotExist` error ``` <class 'dcim.models.Interface.DoesNotExist'> Interface matching query does not exist ```
adam added the pending closure label 2025-12-29 18:23:27 +01:00
adam closed this issue 2025-12-29 18:23:27 +01:00
Author
Owner

@kobayashi commented on GitHub (Oct 3, 2019):

How can I reproduce this? when I try, delete operation works fine to me with the same netbox version.
Can you let me know the step in detail like parameters to reproduce?

@kobayashi commented on GitHub (Oct 3, 2019): How can I reproduce this? when I try, delete operation works fine to me with the same netbox version. Can you let me know the step in detail like parameters to reproduce?
Author
Owner

@dgarros commented on GitHub (Oct 7, 2019):

Here is the full trace, hope this help

Request Method: | POST
-- | --
http://<server_address>/dcim/devices/delete/?q=&region=demo-build-network&mac_address=&has_primary_ip=&local_context_data=&virtual_chassis_member=&console_ports=&console_server_ports=&power_ports=&power_outlets=&interfaces=&pass_through_ports=&cf_dev_pb_vlan_management=
2.2.5
DoesNotExist
Interface matching query does not exist.
/usr/local/lib/python3.6/site-packages/django/db/models/query.py in get, line 408
/usr/bin/python3.6
3.6.8
['/opt/netbox/netbox',  '/usr/local/bin',  '/usr/lib64/python36.zip',  '/usr/lib64/python3.6',  '/usr/lib64/python3.6/lib-dynload',  '/usr/local/lib64/python3.6/site-packages',  '/usr/local/lib/python3.6/site-packages',  '/usr/local/lib/python3.6/site-packages/pip-19.2.3-py3.6.egg',  '/usr/local/lib/python3.6/site-packages/gunicorn-19.9.0-py3.6.egg',  '/usr/lib64/python3.6/site-packages',  '/usr/lib/python3.6/site-packages']
Mon, 7 Oct 2019 21:04:18 +0000
Traceback:

File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py" in __get__
  164.             rel_obj = self.field.get_cached_value(instance)

File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/mixins.py" in get_cached_value
  13.             return instance._state.fields_cache[cache_name]

During handling of the above exception ('_connected_interface'), another exception occurred:

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/opt/netbox/netbox/extras/middleware.py" in __call__
  112.             enqueue_webhooks(obj, request.user, request.id, objectchange.action)

File "/opt/netbox/netbox/extras/webhooks.py" in enqueue_webhooks
  47.                 serializer.data,

File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py" in data
  563.         ret = super(Serializer, self).data

File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py" in data
  262.                 self._data = self.to_representation(self.instance)

File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py" in to_representation
  530.                 ret[field.field_name] = field.to_representation(attribute)

File "/usr/local/lib/python3.6/site-packages/rest_framework/fields.py" in to_representation
  1889.         return method(value)

File "/opt/netbox/netbox/dcim/api/serializers.py" in get_connected_endpoint_type
  34.         if hasattr(obj, 'connected_endpoint') and obj.connected_endpoint is not None:

File "/opt/netbox/netbox/dcim/models.py" in connected_endpoint
  2369.         if self._connected_interface:

File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py" in __get__
  178.                 rel_obj = self.get_object(instance)

File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py" in get_object
  298.         return super().get_object(instance)

File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py" in get_object
  145.         return qs.get(self.field.get_reverse_related_filter(instance))

File "/usr/local/lib/python3.6/site-packages/cacheops/query.py" in get
  356.         return qs._no_monkey.get(qs, *args, **kwargs)

File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py" in get
  408.                 self.model._meta.object_name

Exception Type: DoesNotExist at /dcim/devices/delete/
Exception Value: Interface matching query does not exist.
@dgarros commented on GitHub (Oct 7, 2019): Here is the full trace, hope this help ``` Request Method: | POST -- | -- http://<server_address>/dcim/devices/delete/?q=&region=demo-build-network&mac_address=&has_primary_ip=&local_context_data=&virtual_chassis_member=&console_ports=&console_server_ports=&power_ports=&power_outlets=&interfaces=&pass_through_ports=&cf_dev_pb_vlan_management= 2.2.5 DoesNotExist Interface matching query does not exist. /usr/local/lib/python3.6/site-packages/django/db/models/query.py in get, line 408 /usr/bin/python3.6 3.6.8 ['/opt/netbox/netbox', '/usr/local/bin', '/usr/lib64/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', '/usr/local/lib64/python3.6/site-packages', '/usr/local/lib/python3.6/site-packages', '/usr/local/lib/python3.6/site-packages/pip-19.2.3-py3.6.egg', '/usr/local/lib/python3.6/site-packages/gunicorn-19.9.0-py3.6.egg', '/usr/lib64/python3.6/site-packages', '/usr/lib/python3.6/site-packages'] Mon, 7 Oct 2019 21:04:18 +0000 ``` ``` Traceback: File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py" in __get__ 164. rel_obj = self.field.get_cached_value(instance) File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/mixins.py" in get_cached_value 13. return instance._state.fields_cache[cache_name] During handling of the above exception ('_connected_interface'), another exception occurred: File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner 34. response = get_response(request) File "/opt/netbox/netbox/extras/middleware.py" in __call__ 112. enqueue_webhooks(obj, request.user, request.id, objectchange.action) File "/opt/netbox/netbox/extras/webhooks.py" in enqueue_webhooks 47. serializer.data, File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py" in data 563. ret = super(Serializer, self).data File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py" in data 262. self._data = self.to_representation(self.instance) File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py" in to_representation 530. ret[field.field_name] = field.to_representation(attribute) File "/usr/local/lib/python3.6/site-packages/rest_framework/fields.py" in to_representation 1889. return method(value) File "/opt/netbox/netbox/dcim/api/serializers.py" in get_connected_endpoint_type 34. if hasattr(obj, 'connected_endpoint') and obj.connected_endpoint is not None: File "/opt/netbox/netbox/dcim/models.py" in connected_endpoint 2369. if self._connected_interface: File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py" in __get__ 178. rel_obj = self.get_object(instance) File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py" in get_object 298. return super().get_object(instance) File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py" in get_object 145. return qs.get(self.field.get_reverse_related_filter(instance)) File "/usr/local/lib/python3.6/site-packages/cacheops/query.py" in get 356. return qs._no_monkey.get(qs, *args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py" in get 408. self.model._meta.object_name Exception Type: DoesNotExist at /dcim/devices/delete/ Exception Value: Interface matching query does not exist. ```
Author
Owner

@DanSheps commented on GitHub (Oct 8, 2019):

This could possibly be a caching issue, however:

I was unable to reproduce this following the exact steps on https://master.netbox.dansheps.com

Please provide reproducible steps.

@DanSheps commented on GitHub (Oct 8, 2019): This could possibly be a caching issue, however: I was unable to reproduce this following the exact steps on https://master.netbox.dansheps.com Please provide reproducible steps.
Author
Owner

@lampwins commented on GitHub (Oct 8, 2019):

From the traceback, we can see that this is related to webhooks. To reproduce it, you will need to have to a webhook enabled.

@lampwins commented on GitHub (Oct 8, 2019): From the traceback, we can see that this is related to webhooks. To reproduce it, you will need to have to a webhook enabled.
Author
Owner

@kobayashi commented on GitHub (Oct 9, 2019):

I tried to again with webhook enabled environment. The delete operation with interfaces works and my worker received all delete events through webhook.
Here is my steps

  • create device1
  • create device2
  • create interfaces1 and interface2 in both devices
  • connect interface1,2 in device1 to interface1,2 in deviece2
  • delete device1

I might need add some data to somewhere to reproduce.

Please let me know your step in detail. @dgarros

The tested environment:

  • Python version: 3.7.4
  • NetBox version: 2.6.5
@kobayashi commented on GitHub (Oct 9, 2019): I tried to again with webhook enabled environment. The delete operation with interfaces works and my worker received all delete events through webhook. Here is my steps - create device1 - create device2 - create interfaces1 and interface2 in both devices - connect interface1,2 in device1 to interface1,2 in deviece2 - delete device1 I might need add some data to somewhere to reproduce. Please let me know your step in detail. @dgarros The tested environment: - Python version: 3.7.4 - NetBox version: 2.6.5
Author
Owner

@DanSheps commented on GitHub (Oct 10, 2019):

Can you give us your webhook configuration as well @dgarros

@DanSheps commented on GitHub (Oct 10, 2019): Can you give us your webhook configuration as well @dgarros
Author
Owner

@dgarros commented on GitHub (Oct 11, 2019):

The issue is present when we have a webhook for dcim>interface configured with Create/Update/Delete
I tried to disable the webhook and the issue is not present anymore

Right now the webhook endpoint is down, not sure if that makes a difference or not

@dgarros commented on GitHub (Oct 11, 2019): The issue is present when we have a webhook for dcim>interface configured with Create/Update/Delete I tried to disable the webhook and the issue is not present anymore Right now the webhook endpoint is down, not sure if that makes a difference or not
Author
Owner

@kobayashi commented on GitHub (Oct 11, 2019):

I was trying with webhook configured as follow

  • object types: dcim.device, dcim.interface
  • set only type delete
@kobayashi commented on GitHub (Oct 11, 2019): I was trying with webhook configured as follow - object types: dcim.device, dcim.interface - set only type delete
Author
Owner

@jeremystretch commented on GitHub (Oct 23, 2019):

@dgarros Can you try testing this against the 3309-changelog-middleware branch? I have a feeling this might have been fixed inadvertently by #3632.

@jeremystretch commented on GitHub (Oct 23, 2019): @dgarros Can you try testing this against the `3309-changelog-middleware` branch? I have a feeling this might have been fixed inadvertently by #3632.
Author
Owner

@jeremystretch commented on GitHub (Oct 25, 2019):

Marking this as blocked pending testing of the changes to the middleware merged in #3632

@jeremystretch commented on GitHub (Oct 25, 2019): Marking this as blocked pending testing of the changes to the middleware merged in #3632
Author
Owner

@dgarros commented on GitHub (Oct 25, 2019):

@jeremystretch I tested the latest code in develop and the issue is still present for me.
I can provide a setup where the problem is present if that can help

@dgarros commented on GitHub (Oct 25, 2019): @jeremystretch I tested the latest code in `develop` and the issue is still present for me. I can provide a setup where the problem is present if that can help
Author
Owner

@jeremystretch commented on GitHub (Oct 25, 2019):

@dgarros All reported bugs need to be reproducible in a stock release. If you can determine the exact scenario which triggers the bug, please update the "steps to reproduce" above so that others can try as well.

@jeremystretch commented on GitHub (Oct 25, 2019): @dgarros All reported bugs need to be reproducible in a stock release. If you can determine the exact scenario which triggers the bug, please update the "steps to reproduce" above so that others can try as well.
Author
Owner

@stale[bot] commented on GitHub (Dec 6, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@stale[bot] commented on GitHub (Dec 6, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@stale[bot] commented on GitHub (Dec 13, 2019):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@stale[bot] commented on GitHub (Dec 13, 2019): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2922