From 3e919022ac00dd2327e56178ebb4dc9a7b7cd211 Mon Sep 17 00:00:00 2001
From: Calum Mackervoy <c.mackervoy@gmail.com>
Date: Mon, 21 Sep 2020 17:31:00 +0000
Subject: [PATCH] bugfix: catching ObjectDoesNotExist in notifications listener

---
 djangoldp_notification/models.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/djangoldp_notification/models.py b/djangoldp_notification/models.py
index 44aba25..337e888 100644
--- a/djangoldp_notification/models.py
+++ b/djangoldp_notification/models.py
@@ -3,6 +3,7 @@ import logging
 import requests
 from django.conf import settings
 from django.core.mail import send_mail
+from django.core.exceptions import ObjectDoesNotExist
 from django.db import models
 from django.db.models.signals import post_save, post_delete
 from django.dispatch import receiver
@@ -123,11 +124,13 @@ def send_notification(sender, instance, **kwargs):
                     (not subscription.is_backlink or not kwargs.get("created")):
                 # I may have configured to send the subscription to a foreign key
                 if subscription.field is not None and len(subscription.field) > 1:
-                    instance = getattr(instance, subscription.field, instance)
                     try:
+                        instance = getattr(instance, subscription.field, instance)
                         url_resource = settings.BASE_URL + Model.resource_id(instance)
                     except NoReverseMatch:
                         continue
+                    except ObjectDoesNotExist:
+                        continue
 
                 process = Thread(target=send_request, args=[subscription.inbox, url_resource, instance,
                                                             kwargs.get("created", False)])
-- 
GitLab