Cannot delete an ObjectType #11433

Closed
opened 2025-12-29 21:45:10 +01:00 by adam · 0 comments
Owner

Originally created by @arthanson on GitHub (Jul 31, 2025).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

NetBox Version

feature @ ???

Python Version

3.10

Steps to Reproduce

Try to delete an ObjectType, easiest way is in shell with the following:

from django.contrib.contenttypes.models import ContentType
from core.models import ObjectType

kwargs = {'app_label': 'foo', 'model': 'bar',}
ct = ContentType.objects.create(**kwargs)
ot = ObjectType.objects.create(**kwargs)
ot.delete()

or can add a test to ObjectTypeTest:

    def test_delete(self):
        """
        Test that an ObjectType deleted.
        """
        kwargs = {
            'app_label': 'foo',
            'model': 'bar',
        }
        ct = ContentType.objects.create(**kwargs)
        ot = ObjectType.objects.create(**kwargs)
        ot.delete()

Also tried to delete the ContentType and receive the same error.

Expected Behavior

ObjectType will get deleted

Observed Behavior

Receive the following error

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/models/base.py", line 1281, in delete
    return collector.delete()
           ~~~~~~~~~~~~~~~~^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/models/deletion.py", line 458, in delete
    signals.pre_delete.send(
    ~~~~~~~~~~~~~~~~~~~~~~~^
        sender=model,
        ^^^^^^^^^^^^^
    ...<2 lines>...
        origin=self.origin,
        ^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/dispatch/dispatcher.py", line 189, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/Users/ahanson/dev/work/netbox/netbox/extras/signals.py", line 152, in notify_object_changed
    if not has_feature(instance, 'notifications'):
           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/netbox/netbox/models/features.py", line 682, in has_feature
    ot = ObjectType.objects.get_for_model(model_or_ct.model_class())
  File "/Users/ahanson/dev/work/netbox/netbox/core/models/object_types.py", line 67, in get_for_model
    opts = self._get_opts(model, for_concrete_model)
  File "/Users/ahanson/dev/work/netbox/netbox/core/models/object_types.py", line 59, in _get_opts
    model = model._meta.concrete_model
            ^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '_meta'

When doing it in CustomObjects get the following which I'm not sure why different but it seems to go into the eventing code for ContentType:

Traceback (most recent call last):
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/netbox/netbox/views/generic/base.py", line 26, in dispatch
    return super().dispatch(request, *args, **kwargs)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/netbox/utilities/views.py", line 125, in dispatch
    return super().dispatch(request, *args, **kwargs)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/netbox/utilities/views.py", line 39, in dispatch
    return super().dispatch(request, *args, **kwargs)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
  File "/Users/ahanson/dev/work/netbox/netbox/netbox/views/generic/object_views.py", line 481, in post
    obj.delete()
    ~~~~~~~~~~^^
  File "/Users/ahanson/dev/work/netbox-custom-objects/netbox_custom_objects/models.py", line 505, in delete
    ).delete()
      ~~~~~~^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/models/base.py", line 1281, in delete
    return collector.delete()
           ~~~~~~~~~~~~~~~~^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/models/deletion.py", line 458, in delete
    signals.pre_delete.send(
    ~~~~~~~~~~~~~~~~~~~~~~~^
        sender=model,
        ^^^^^^^^^^^^^
    ...<2 lines>...
        origin=self.origin,
        ^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/dispatch/dispatcher.py", line 189, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/Users/ahanson/dev/work/netbox/netbox/core/signals.py", line 223, in handle_deleted_object
    enqueue_event(queue, instance, request.user, request.id, OBJECT_DELETED)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/netbox/extras/events.py", line 78, in enqueue_event
    'data': serialize_for_event(instance),
            ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/netbox/extras/events.py", line 29, in serialize_for_event
    serializer_class = get_serializer_for_model(instance.__class__)
  File "/Users/ahanson/dev/work/netbox/netbox/utilities/api.py", line 38, in get_serializer_for_model
    raise SerializerNotFound(
        f"Could not determine serializer for {app_label}.{model_name} with prefix '{prefix}'"
    )
netbox.api.exceptions.SerializerNotFound: Could not determine serializer for contenttypes.ContentType with prefix ''
Originally created by @arthanson on GitHub (Jul 31, 2025). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### NetBox Version `feature` @ ??? ### Python Version 3.10 ### Steps to Reproduce Try to delete an ObjectType, easiest way is in shell with the following: ``` from django.contrib.contenttypes.models import ContentType from core.models import ObjectType kwargs = {'app_label': 'foo', 'model': 'bar',} ct = ContentType.objects.create(**kwargs) ot = ObjectType.objects.create(**kwargs) ot.delete() ``` or can add a test to ObjectTypeTest: ``` def test_delete(self): """ Test that an ObjectType deleted. """ kwargs = { 'app_label': 'foo', 'model': 'bar', } ct = ContentType.objects.create(**kwargs) ot = ObjectType.objects.create(**kwargs) ot.delete() ``` Also tried to delete the ContentType and receive the same error. ### Expected Behavior ObjectType will get deleted ### Observed Behavior Receive the following error ``` Traceback (most recent call last): File "<console>", line 1, in <module> File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/models/base.py", line 1281, in delete return collector.delete() ~~~~~~~~~~~~~~~~^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/models/deletion.py", line 458, in delete signals.pre_delete.send( ~~~~~~~~~~~~~~~~~~~~~~~^ sender=model, ^^^^^^^^^^^^^ ...<2 lines>... origin=self.origin, ^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/dispatch/dispatcher.py", line 189, in send response = receiver(signal=self, sender=sender, **named) File "/Users/ahanson/dev/work/netbox/netbox/extras/signals.py", line 152, in notify_object_changed if not has_feature(instance, 'notifications'): ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/netbox/netbox/models/features.py", line 682, in has_feature ot = ObjectType.objects.get_for_model(model_or_ct.model_class()) File "/Users/ahanson/dev/work/netbox/netbox/core/models/object_types.py", line 67, in get_for_model opts = self._get_opts(model, for_concrete_model) File "/Users/ahanson/dev/work/netbox/netbox/core/models/object_types.py", line 59, in _get_opts model = model._meta.concrete_model ^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute '_meta' ``` When doing it in CustomObjects get the following which I'm not sure why different but it seems to go into the eventing code for ContentType: ``` Traceback (most recent call last): File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/views/generic/base.py", line 104, in view return self.dispatch(request, *args, **kwargs) ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/netbox/netbox/views/generic/base.py", line 26, in dispatch return super().dispatch(request, *args, **kwargs) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/netbox/utilities/views.py", line 125, in dispatch return super().dispatch(request, *args, **kwargs) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/netbox/utilities/views.py", line 39, in dispatch return super().dispatch(request, *args, **kwargs) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/views/generic/base.py", line 143, in dispatch return handler(request, *args, **kwargs) File "/Users/ahanson/dev/work/netbox/netbox/netbox/views/generic/object_views.py", line 481, in post obj.delete() ~~~~~~~~~~^^ File "/Users/ahanson/dev/work/netbox-custom-objects/netbox_custom_objects/models.py", line 505, in delete ).delete() ~~~~~~^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/models/base.py", line 1281, in delete return collector.delete() ~~~~~~~~~~~~~~~~^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/models/deletion.py", line 458, in delete signals.pre_delete.send( ~~~~~~~~~~~~~~~~~~~~~~~^ sender=model, ^^^^^^^^^^^^^ ...<2 lines>... origin=self.origin, ^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/dispatch/dispatcher.py", line 189, in send response = receiver(signal=self, sender=sender, **named) File "/Users/ahanson/dev/work/netbox/netbox/core/signals.py", line 223, in handle_deleted_object enqueue_event(queue, instance, request.user, request.id, OBJECT_DELETED) ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/netbox/extras/events.py", line 78, in enqueue_event 'data': serialize_for_event(instance), ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/netbox/extras/events.py", line 29, in serialize_for_event serializer_class = get_serializer_for_model(instance.__class__) File "/Users/ahanson/dev/work/netbox/netbox/utilities/api.py", line 38, in get_serializer_for_model raise SerializerNotFound( f"Could not determine serializer for {app_label}.{model_name} with prefix '{prefix}'" ) netbox.api.exceptions.SerializerNotFound: Could not determine serializer for contenttypes.ContentType with prefix '' ```
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:45:10 +01:00
adam closed this issue 2025-12-29 21:45:10 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11433