Unable to delete device after upgrade to 2.4.3 #1935

Closed
opened 2025-12-29 17:20:41 +01:00 by adam · 3 comments
Owner

Originally created by @jnfohr on GitHub (Aug 13, 2018).

Environment

  • Python version: 3.5.2
  • NetBox version: 2.4.3

Steps to Reproduce

  • Upgrade from 2.3.6 to 2.4.3
  • Clic "Delete this device" from web UI for an already existing device and hit "Confirm"

Expected Behavior

  • Deletion of the device

Observed Behavior

Error message:

<class 'dcim.models.DoesNotExist'>

Device matching query does not exist.

And device is not deleted. This is not happening for all existing devices.

Stacktrace

Internal Server Error: /dcim/devices/187/delete/

DoesNotExist at /dcim/devices/187/delete/
Device matching query does not exist.

Request Method: POST
Request URL: http://netbox/dcim/devices/187/delete/
Django Version: 2.0.8
Python Executable: /usr/bin/python3
Python Version: 3.5.2
Python Path: ['/opt/netbox/netbox', '/opt/netbox/netbox', '/usr/local/bin', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist-packages']
Server time: Mon, 13 Aug 2018 13:35:04 +0000
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'corsheaders',
 'debug_toolbar',
 'django_filters',
 'django_tables2',
 'mptt',
 'rest_framework',
 'taggit',
 'taggit_serializer',
 'timezone_field',
 'circuits',
 'dcim',
 'ipam',
 'extras',
 'secrets',
 'tenancy',
 'users',
 'utilities',
 'virtualization',
 'drf_yasg']
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'utilities.middleware.ExceptionHandlingMiddleware',
 'utilities.middleware.LoginRequiredMiddleware',
 'utilities.middleware.APIVersionMiddleware',
 'extras.middleware.ObjectChangeMiddleware')


Traceback:

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

File "/usr/local/lib/python3.5/dist-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 ('device'), another exception occurred:

File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)

File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response
  128.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response
  126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python3.5/dist-packages/django/views/generic/base.py" in view
  69.             return self.dispatch(request, *args, **kwargs)

File "/usr/local/lib/python3.5/dist-packages/django/contrib/auth/mixins.py" in dispatch
  85.         return super().dispatch(request, *args, **kwargs)

File "/usr/local/lib/python3.5/dist-packages/django/views/generic/base.py" in dispatch
  89.         return handler(request, *args, **kwargs)

File "/opt/netbox/netbox/utilities/views.py" in post
  280.                 obj.delete()

File "/usr/local/lib/python3.5/dist-packages/django/db/models/base.py" in delete
  891.         return collector.delete()

File "/usr/local/lib/python3.5/dist-packages/django/db/models/deletion.py" in delete
  307.                             sender=model, instance=obj, using=self.using

File "/usr/local/lib/python3.5/dist-packages/django/dispatch/dispatcher.py" in send
  178.             for receiver in self._live_receivers(sender)

File "/usr/local/lib/python3.5/dist-packages/django/dispatch/dispatcher.py" in <listcomp>
  178.             for receiver in self._live_receivers(sender)

File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py" in _curried
  11.         return _curried_func(*(args + moreargs), **dict(kwargs, **morekwargs))

File "/opt/netbox/netbox/extras/middleware.py" in _record_object_deleted
  37.         instance.log_change(request.user, request.id, OBJECTCHANGE_ACTION_DELETE)

File "/opt/netbox/netbox/dcim/models.py" in log_change
  2088.                 related_object=interface.parent,

File "/opt/netbox/netbox/dcim/models.py" in parent
  1960.         return self.device or self.virtual_machine

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

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

File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py" in get
  403.                 self.model._meta.object_name

Exception Type: DoesNotExist at /dcim/devices/187/delete/
Exception Value: Device matching query does not exist.
Originally created by @jnfohr on GitHub (Aug 13, 2018). <!-- NOTE: This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.5.2 * NetBox version: 2.4.3 <!-- Describe in detail the steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). --> ### Steps to Reproduce - Upgrade from 2.3.6 to 2.4.3 - Clic "Delete this device" from web UI for an already existing device and hit "Confirm" <!-- What did you expect to happen? --> ### Expected Behavior - Deletion of the device <!-- What happened instead? --> ### Observed Behavior Error message: > <class 'dcim.models.DoesNotExist'> > > Device matching query does not exist. And device is not deleted. This is not happening for all existing devices. **Stacktrace** Internal Server Error: /dcim/devices/187/delete/ DoesNotExist at /dcim/devices/187/delete/ Device matching query does not exist. ``` Request Method: POST Request URL: http://netbox/dcim/devices/187/delete/ Django Version: 2.0.8 Python Executable: /usr/bin/python3 Python Version: 3.5.2 Python Path: ['/opt/netbox/netbox', '/opt/netbox/netbox', '/usr/local/bin', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist-packages'] Server time: Mon, 13 Aug 2018 13:35:04 +0000 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.humanize', 'corsheaders', 'debug_toolbar', 'django_filters', 'django_tables2', 'mptt', 'rest_framework', 'taggit', 'taggit_serializer', 'timezone_field', 'circuits', 'dcim', 'ipam', 'extras', 'secrets', 'tenancy', 'users', 'utilities', 'virtualization', 'drf_yasg'] Installed Middleware: ('debug_toolbar.middleware.DebugToolbarMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', 'utilities.middleware.ExceptionHandlingMiddleware', 'utilities.middleware.LoginRequiredMiddleware', 'utilities.middleware.APIVersionMiddleware', 'extras.middleware.ObjectChangeMiddleware') Traceback: File "/usr/local/lib/python3.5/dist-packages/django/db/models/fields/related_descriptors.py" in __get__ 158. rel_obj = self.field.get_cached_value(instance) File "/usr/local/lib/python3.5/dist-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 ('device'), another exception occurred: File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py" in inner 35. response = get_response(request) File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response 128. response = self.process_exception_by_middleware(e, request) File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response 126. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python3.5/dist-packages/django/views/generic/base.py" in view 69. return self.dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.5/dist-packages/django/contrib/auth/mixins.py" in dispatch 85. return super().dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.5/dist-packages/django/views/generic/base.py" in dispatch 89. return handler(request, *args, **kwargs) File "/opt/netbox/netbox/utilities/views.py" in post 280. obj.delete() File "/usr/local/lib/python3.5/dist-packages/django/db/models/base.py" in delete 891. return collector.delete() File "/usr/local/lib/python3.5/dist-packages/django/db/models/deletion.py" in delete 307. sender=model, instance=obj, using=self.using File "/usr/local/lib/python3.5/dist-packages/django/dispatch/dispatcher.py" in send 178. for receiver in self._live_receivers(sender) File "/usr/local/lib/python3.5/dist-packages/django/dispatch/dispatcher.py" in <listcomp> 178. for receiver in self._live_receivers(sender) File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py" in _curried 11. return _curried_func(*(args + moreargs), **dict(kwargs, **morekwargs)) File "/opt/netbox/netbox/extras/middleware.py" in _record_object_deleted 37. instance.log_change(request.user, request.id, OBJECTCHANGE_ACTION_DELETE) File "/opt/netbox/netbox/dcim/models.py" in log_change 2088. related_object=interface.parent, File "/opt/netbox/netbox/dcim/models.py" in parent 1960. return self.device or self.virtual_machine File "/usr/local/lib/python3.5/dist-packages/django/db/models/fields/related_descriptors.py" in __get__ 164. rel_obj = self.get_object(instance) File "/usr/local/lib/python3.5/dist-packages/django/db/models/fields/related_descriptors.py" in get_object 139. return qs.get(self.field.get_reverse_related_filter(instance)) File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py" in get 403. self.model._meta.object_name Exception Type: DoesNotExist at /dcim/devices/187/delete/ Exception Value: Device matching query does not exist. ```
adam added the type: bugstatus: accepted labels 2025-12-29 17:20:41 +01:00
adam closed this issue 2025-12-29 17:20:42 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 13, 2018):

This is not happening for all existing devices.

Could you please list the steps necessary to recreate the error, beginning with the creation of a new device? This is necessary to develop a fix.

Looks related to #2323.

@jeremystretch commented on GitHub (Aug 13, 2018): > This is not happening for all existing devices. Could you please list the steps necessary to recreate the error, beginning with the creation of a new device? This is necessary to develop a fix. Looks related to #2323.
Author
Owner

@jnfohr commented on GitHub (Aug 14, 2018):

When creating a new device i'm not able to recreate the issue.

I'v been doing some tests and found out that the error disappears and i'm able to delete the device once i disconnect or delete the network interfaces (disconnect is enough). But changing the network interface parameters (name, status, type) has no effect.

What's surprising is that it just occurs with a few devices and is hardly reproductible. Deleting the switch facing the device while the interfaces are connected is possible and does not return any error.

@jnfohr commented on GitHub (Aug 14, 2018): When creating a new device i'm not able to recreate the issue. I'v been doing some tests and found out that the error disappears and i'm able to delete the device once i disconnect or delete the network interfaces (disconnect is enough). But changing the network interface parameters (name, status, type) has no effect. What's surprising is that it just occurs with a few devices and is hardly reproductible. Deleting the switch facing the device while the interfaces are connected is possible and does not return any error.
Author
Owner

@jeremystretch commented on GitHub (Aug 22, 2018):

I can't recreate this but we should be able to avoid it by catching the exception in InterfaceConnection.log_change().

@jeremystretch commented on GitHub (Aug 22, 2018): I can't recreate this but we should be able to avoid it by catching the exception in `InterfaceConnection.log_change()`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1935