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

StagedChange: SerializerNotFound #13640

Closed
minitriga opened this issue Aug 31, 2023 · 6 comments
Closed

StagedChange: SerializerNotFound #13640

minitriga opened this issue Aug 31, 2023 · 6 comments
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: blocked Another issue or external requirement is preventing implementation status: under review Further discussion is needed to determine this issue's scope and/or implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@minitriga
Copy link
Contributor

minitriga commented Aug 31, 2023

NetBox version

v3.5.8

Python version

3.8

Steps to Reproduce

Create a staged change and delete via the UI in a plugin. There is no UI for the StagedChange model but when using it in a plugin and deleting a staged change the following is raised:
netbox.api.exceptions.SerializerNotFound: Could not determine serializer for extras.StagedChange with prefix ''

Expected Behavior

I expect that the deletion of a branch or staged change would not fail. I think this is due to the model has the following mixin ChangeLoggedModel.

Observed Behavior

extras.api.serializers.StagedChangeSerializer
Internal Server Error: /plugins/ipfabric/sync/12/delete/
Traceback (most recent call last):
  File "/opt/netbox/netbox/utilities/api.py", line 33, in get_serializer_for_model
    return dynamic_import(serializer_name)
  File "/opt/netbox/netbox/utilities/utils.py", line 126, in dynamic_import
    mod = getattr(mod, comp)
AttributeError: module 'extras.api.serializers' has no attribute 'StagedChangeSerializer'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
    response = get_response(request)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 103, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/netbox/netbox/netbox/views/generic/base.py", line 26, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/netbox/netbox/utilities/views.py", line 99, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 142, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/netbox/netbox/netbox/views/generic/object_views.py", line 375, in post
    obj.delete()
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1118, in delete
    return collector.delete()
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/deletion.py", line 458, in delete
    signals.pre_delete.send(
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 176, in send
    return [
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 177, in <listcomp>
    (receiver, receiver(signal=self, sender=sender, **named))
  File "/opt/netbox/netbox/extras/signals.py", line 118, in handle_deleted_object
    enqueue_object(queue, instance, request.user, request.id, ObjectChangeActionChoices.ACTION_DELETE)
  File "/opt/netbox/netbox/extras/webhooks.py", line 73, in enqueue_object
    'data': serialize_for_webhook(instance),
  File "/opt/netbox/netbox/extras/webhooks.py", line 22, in serialize_for_webhook
    serializer_class = get_serializer_for_model(instance.__class__)
  File "/opt/netbox/netbox/utilities/api.py", line 35, in get_serializer_for_model
    raise SerializerNotFound(
netbox.api.exceptions.SerializerNotFound: Could not determine serializer for extras.StagedChange with prefix ''
@minitriga minitriga added the type: bug A confirmed report of unexpected behavior in the application label Aug 31, 2023
@minitriga
Copy link
Contributor Author

I can implement some serializers for Branch and StagedChange models.

@minitriga
Copy link
Contributor Author

Having looked how many staged changes there can be I dont think its worth having change ChangeLoggedModel on it. For example when ingesting some customer information using the staging method there can be up to 100k+ objects being altered. Deleting these takes very long due to the ChangeLoggedModel process.

@jeremystretch jeremystretch added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Sep 11, 2023
@jeremystretch jeremystretch added the severity: medium Results in substantial degraded or broken functionality for specfic workflows label Sep 21, 2023
@arthanson
Copy link
Collaborator

@minitriga the SerializerNotFound can remain in this issue, for removing ChangeLoggedModel on StagedChange - that should be opened as a feature-request as it will cause database changes and need to go into a point release.

@arthanson arthanson added the status: blocked Another issue or external requirement is preventing implementation label Dec 4, 2023
@arthanson
Copy link
Collaborator

@minitriga creating new deprecation #14424 as this removes functionality it would need to be discussed as a deprecation. Marking this as blocked on that issue. Blocked by #14424

@arthanson
Copy link
Collaborator

This is fixed via #14424 so closing.

@minitriga
Copy link
Contributor Author

@arthanson This looks to be still broken in 3.7 I have upgraded and I get the same issue:

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
January 10, 2024 - 15:39:10
Django version 4.2.8, using settings 'netbox.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.

[10/Jan/2024 15:39:17] "GET /plugins/ipfabric/sync/1/ HTTP/1.1" 200 112087
[10/Jan/2024 15:39:19] "GET /plugins/ipfabric/sync/1/delete/ HTTP/1.1" 200 7065
[10/Jan/2024 15:39:19] "GET /__debug__/history_sidebar/?store_id=58e3fd2b7f8444b29927866e81aba754 HTTP/1.1" 200 9502
Internal Server Error: /plugins/ipfabric/sync/1/delete/
Traceback (most recent call last):
  File "/opt/netbox/netbox/utilities/api.py", line 32, in get_serializer_for_model
    return dynamic_import(serializer_name)
  File "/opt/netbox/netbox/utilities/utils.py", line 126, in dynamic_import
    mod = getattr(mod, comp)
AttributeError: module 'extras.api.serializers' has no attribute 'StagedChangeSerializer'. Did you mean: 'ObjectChangeSerializer'?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/netbox/netbox/netbox/views/generic/base.py", line 26, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/netbox/netbox/utilities/views.py", line 99, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/netbox/netbox/netbox/views/generic/object_views.py", line 420, in post
    obj.delete()
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1132, in delete
    return collector.delete()
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/deletion.py", line 463, in delete
    signals.pre_delete.send(
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 176, in send
    return [
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 177, in <listcomp>
    (receiver, receiver(signal=self, sender=sender, **named))
  File "/opt/netbox/netbox/extras/signals.py", line 125, in handle_deleted_object
    enqueue_object(queue, instance, request.user, request.id, ObjectChangeActionChoices.ACTION_DELETE)
  File "/opt/netbox/netbox/extras/events.py", line 67, in enqueue_object
    'data': serialize_for_event(instance),
  File "/opt/netbox/netbox/extras/events.py", line 28, in serialize_for_event
    serializer_class = get_serializer_for_model(instance.__class__)
  File "/opt/netbox/netbox/utilities/api.py", line 34, in get_serializer_for_model
    raise SerializerNotFound(
netbox.api.exceptions.SerializerNotFound: Could not determine serializer for extras.StagedChange with prefix ''
[10/Jan/2024 15:39:20] "POST /plugins/ipfabric/sync/1/delete/ HTTP/1.1" 500 172606
(venv) root@asd:/opt/netbox/netbox# python3 manage.py nbshell
### NetBox interactive shell (sa-alex-gittings-netboxdev)
### Python 3.10.12 | Django 4.2.8 | NetBox 3.7.0
### lsmodels() will show available models. Use help(<model>) for more info.
>>> from django.conf import settings
>>> settings.VERSION
'3.7.0'

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: blocked Another issue or external requirement is preventing implementation status: under review Further discussion is needed to determine this issue's scope and/or implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

3 participants