From be251830ec0bba4fdcccb91386a3995e4a493e23 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 12 Nov 2024 19:09:56 +0530 Subject: [PATCH] only get `environment` if instance exists --- api/audit/tasks.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/audit/tasks.py b/api/audit/tasks.py index 0a94efa436ef..5f058b47a68b 100644 --- a/api/audit/tasks.py +++ b/api/audit/tasks.py @@ -89,7 +89,9 @@ def create_audit_log_from_historical_record( if not (history_user or override_author or history_instance.master_api_key): return - environment, project = instance.get_environment_and_project() + environment = project = None + if instance.__class__.objects.filter(pk=instance.pk).exists(): + environment, project = instance.get_environment_and_project() related_object_id = instance.get_audit_log_related_object_id(history_instance) related_object_type = instance.get_audit_log_related_object_type(history_instance)