nautobot / nautobot

Network Source of Truth & Network Automation Platform
https://docs.nautobot.com
Apache License 2.0
1.07k stars 283 forks source link

[1.3] Change logging needs to handle models with no associated serializer #1440

Closed glennmatthews closed 2 years ago

glennmatthews commented 2 years ago

Environment

Steps to Reproduce

  1. Have a model that is change-logged (implements to_objectchange or inherits from ChangeLoggedModel) but has no associated REST API serializer
  2. Create, update, or delete an instance of this model.

Expected Behavior

Change logging to succeed.

Observed Behavior

...
  File "/source/nautobot/extras/signals.py", line 72, in _handle_changed_object
    objectchange = instance.to_objectchange(action)
  File "/source/nautobot/extras/models/change_logging.py", line 43, in to_objectchange
    object_data_v2=serialize_object_v2(self),
  File "/source/nautobot/utilities/utils.py", line 152, in serialize_object_v2
    serializer_class = get_serializer_for_model(obj.__class__)
  File "/source/nautobot/utilities/api.py", line 29, in get_serializer_for_model
    "Could not determine serializer for {}.{} with prefix '{}'".format(app_name, model_name, prefix)
nautobot.core.api.exceptions.SerializerNotFound: Could not determine serializer for extras.Job with prefix ''

IMHO the to_objectchange implementation needs to catch the SerializerNotFound exception, possibly log a warning message, and gracefully recover.

glennmatthews commented 2 years ago

Issue introduced by #1389, hence this only applies to next at this time.

bryanculver commented 2 years ago

Merged into next.