netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
16.27k stars 2.59k forks source link

Error occured on virtual chassis deletion #3379

Closed xtprox closed 5 years ago

xtprox commented 5 years ago

Environment

Steps to Reproduce

  1. Create two devices
  2. In Devices view select two new devices and click Create Virtual Chassis
  3. Select master, position/priorities 1 and 2 respectively
  4. Validate that virtual chassis has been created
  5. Open Devices view and select one of Virtual chassis members
  6. Delete virtual chassis from Virtual chassis section in device

Expected Behavior

Virtual chassis device deleted

Observed Behavior

Error appears image

If from Devices view ex-master device selected, it generates the same error. Ex-master device can be deleted from Devices view.

xtprox commented 5 years ago

Additionaly email contents (partially) attached that was sent by IPAM

Internal Server Error: /dcim/devices/194/

DoesNotExist at /dcim/devices/194/
VirtualChassis matching query does not exist.

Request Method: GET
Request URL: https://ipam.sanitized.com/dcim/devices/194/
Django Version: 2.2.3
Python Executable: /usr/bin/python3
Python Version: 3.6.8
Python Path: ['/opt/netbox/netbox', '/opt/netbox-2.6.1/netbox', '/usr/local/bin', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages'] Server time: Wed, 31 Jul 2019 09:26:55 +0000 Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'cacheops',
 'corsheaders',
 'debug_toolbar',
 'django_filters',
 'django_tables2',
 'django_prometheus',
 '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',
 'django_prometheus.middleware.PrometheusBeforeMiddleware',
 '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',
 'django_prometheus.middleware.PrometheusAfterMiddleware')

Traceback:

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

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

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

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

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

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

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

File "/opt/netbox/netbox/dcim/views.py" in get
  929.         if device.virtual_chassis is not None:

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

File "/usr/local/lib/python3.6/dist-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/dist-packages/cacheops/query.py" in get
  356.         return qs._no_monkey.get(qs, *args, **kwargs)

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

Exception Type: DoesNotExist at /dcim/devices/194/ Exception Value: VirtualChassis matching query does not exist.
jeremystretch commented 5 years ago

I'm not able to recreate this on v2.6.1. The virtual chassis is deleted as expected without error.

LuPo commented 5 years ago

I experience the same error as @megazloj

jeremystretch commented 5 years ago

@LuPo please detail the steps necessary to recreate the bug.

xtprox commented 5 years ago

@jeremystretch I've updated actions to reproduce. Also the error recreated on https://master.netbox.dansheps.com/

DanSheps commented 5 years ago

I am wondering if this might be related to caching as well.

I am going to reproduce, disable caching, and reproduce again. Will post results tomorrow.

xtprox commented 5 years ago

FYI, error is also reproducible in NetBox 2.6.2.

jeremystretch commented 5 years ago

@DanSheps any update on this?

DanSheps commented 5 years ago

With Cache:

Create two devices, Test 1 & Test 2 Created VC Deleted VC Error received

Without Cache

Create two devices, Test 1 & Test 2 Created VC Deleted VC No error

Definitely related to caching. I suspect the cache still returns the fact that it is part of the VC but when the cache is searched for the VC it doesn't exist. So, similar to #3382, but in this case since the object doesn't exist it just fails.

I believe we are planning on just dumping the whole cache when we do writes to the database correct? That should be fix this as well.

jeremystretch commented 5 years ago

Sounds good to me but I'll defer to @lampwins for his thoughts. We do need to get this fixed sooner rather than later though.

jeremystretch commented 5 years ago

Rolled into #3428