Skip to content

Commit

Permalink
modellogging catch missing model errors
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrindt committed Oct 23, 2023
1 parent 311f4e2 commit 2e79eef
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ephios/modellogging/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def __init__(self, *args, **kargs):
def custom_hook(self, d):
if d.get("__model__") == "__queryset__":
Model = ContentType.objects.get_for_id(d["contenttype_id"]).model_class()
if Model is None:
return d["strs"]
objects = {obj.pk: obj for obj in Model._base_manager.filter(pk__in=d["pks"])}
return [objects.get(pk, s) for pk, s in zip(d["pks"], d["strs"])]
if d.get("__model__") == "__instance__":
Expand Down
2 changes: 1 addition & 1 deletion ephios/modellogging/recorders.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def serialize(self, action_type: InstanceActionType):
def deserialize(cls, data, model, action_type: InstanceActionType):
try:
self = cls(model._meta.get_field(data["field_name"]))
except FieldDoesNotExist:
except (AttributeError, FieldDoesNotExist):
self = cls(None)
self.label = data["verbose_name"]
else:
Expand Down

0 comments on commit 2e79eef

Please sign in to comment.