From 1a2cb82dffbc6f1f0e5befbfdf199d13d002d0cc Mon Sep 17 00:00:00 2001 From: Masse Date: Wed, 14 Mar 2018 11:44:27 -0400 Subject: [PATCH] Issue-58 When using UserLoggingMiddleware on a model that is also a child model of a django-polymorphic, an ObjectDoesNotExist exception is raised in _disable_audit_log_managers and _enable_audit_log_managers as a side effect of the evaluation. While not the best fix, this patch is minimally invasive, very low risk, and solves the problem. --- audit_log/middleware.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/audit_log/middleware.py b/audit_log/middleware.py index 2a2ceca..3b0acde 100755 --- a/audit_log/middleware.py +++ b/audit_log/middleware.py @@ -1,3 +1,4 @@ +from django.core.exceptions import ObjectDoesNotExist from django.db.models import signals from django.utils.deprecation import MiddlewareMixin from django.utils.functional import curry @@ -11,7 +12,7 @@ def _disable_audit_log_managers(instance): try: if isinstance(getattr(instance, attr), AuditLogManager): getattr(instance, attr).disable_tracking() - except AttributeError: + except (AttributeError, ObjectDoesNotExist): # ObjectDoesNot exist raised with django-polymorphic child models pass @@ -20,7 +21,7 @@ def _enable_audit_log_managers(instance): try: if isinstance(getattr(instance, attr), AuditLogManager): getattr(instance, attr).enable_tracking() - except AttributeError: + except (AttributeError, ObjectDoesNotExist): pass