From 1206b53e6cd1110a4f9c10e5a98308ecf040b61a Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Thu, 8 Apr 2021 10:56:45 -0500 Subject: [PATCH] OAuth: protection against deleted objects Ref https://sentry.io/organizations/read-the-docs/issues/2322520998/?environment=production&project=148442 --- readthedocs/oauth/tasks.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/readthedocs/oauth/tasks.py b/readthedocs/oauth/tasks.py index b74ba8446b1..2e66e0d9092 100644 --- a/readthedocs/oauth/tasks.py +++ b/readthedocs/oauth/tasks.py @@ -53,8 +53,12 @@ def attach_webhook(project_pk, user_pk, integration=None): connections -- that is, projects that do not have a remote repository them and were not set up with a VCS provider. """ - project = Project.objects.get(pk=project_pk) - user = User.objects.get(pk=user_pk) + project = Project.objects.filter(pk=project_pk).first() + user = User.objects.filter(pk=user_pk).first() + + if not project or not user: + return False + project_notification = InvalidProjectWebhookNotification( context_object=project, user=user,