Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DoesNotExist exception triggered when deleting a device with one or more secrets #3927

Closed
jeremystretch opened this issue Jan 15, 2020 · 0 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@jeremystretch
Copy link
Member

Environment

  • Python version: 2.6.12
  • NetBox version: 3.6.8

Steps to Reproduce

  1. Create a device
  2. Assign one or more secrets to the device
  3. Delete the device

Expected Behavior

The device and its associated secrets should be deleted, and the change log should be updated to reflect the deletion of each object.

Observed Behavior

The device and secrets are deleted, however an exception is raised while attempting to record the secrets deletion in the change log:

Internal Server Error: /dcim/devices/1611/delete/
Traceback (most recent call last):
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 164, in __get__
    rel_obj = self.field.get_cached_value(instance)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/fields/mixins.py", line 13, in get_cached_value
    return instance._state.fields_cache[cache_name]
KeyError: 'device'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/jstretch/netbox/netbox/extras/middleware.py", line 110, in __call__
    objectchange = instance.to_objectchange(action)
  File "/home/jstretch/netbox/netbox/utilities/models.py", line 33, in to_objectchange
    object_repr=str(self),
  File "/home/jstretch/netbox/netbox/secrets/models.py", line 362, in __str__
    if self.role and self.device and self.name:
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 178, in __get__
    rel_obj = self.get_object(instance)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 145, in get_object
    return qs.get(self.field.get_reverse_related_filter(instance))
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/cacheops/query.py", line 356, in get
    return qs._no_monkey.get(qs, *args, **kwargs)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/query.py", line 408, in get
    self.model._meta.object_name
dcim.models.Device.DoesNotExist: Device matching query does not exist.

This is due to the __str__() method on Secret attempting to resolve the parent Device, which no longer exists at the point of execution.

@jeremystretch jeremystretch added type: bug A confirmed report of unexpected behavior in the application status: accepted This issue has been accepted for implementation labels Jan 15, 2020
@jeremystretch jeremystretch self-assigned this Jan 15, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

1 participant