From a22ba4859b1d1a682ffa3a12fb6e066da96bfaf4 Mon Sep 17 00:00:00 2001 From: Michael Manfre Date: Wed, 25 Jan 2023 23:20:27 -0500 Subject: [PATCH] Downgrade follow not found to capture_message --- users/models/follow.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/users/models/follow.py b/users/models/follow.py index 3ef4499..d5982c5 100644 --- a/users/models/follow.py +++ b/users/models/follow.py @@ -3,6 +3,7 @@ from typing import Optional import httpx from django.db import models, transaction +from core.exceptions import capture_message from core.ld import canonicalise, get_str_or_id from core.snowflake import Snowflake from stator.models import State, StateField, StateGraph, StatorModel @@ -303,7 +304,14 @@ class Follow(StatorModel): from activities.models import TimelineEvent with transaction.atomic(): - follow = cls.by_ap(data, create=True) + try: + follow = cls.by_ap(data, create=True) + except Identity.DoesNotExist: + capture_message( + "Identity not found for incoming Follow", extras={"data": data} + ) + return + # Force it into remote_requested so we send an accept follow.transition_perform(FollowStates.remote_requested) # Add a timeline event @@ -317,8 +325,13 @@ class Follow(StatorModel): # Resolve source and target and see if a Follow exists (it really should) try: follow = cls.by_ap(data["object"]) - except cls.DoesNotExist: - raise ValueError("No Follow locally for incoming Accept", data) + except (cls.DoesNotExist, Identity.DoesNotExist): + capture_message( + "Follow or Identity not found for incoming Accept", + extras={"data": data}, + ) + return + # Ensure the Accept actor is the Follow's target if data["actor"] != follow.target.actor_uri: raise ValueError("Accept actor does not match its Follow object", data) @@ -337,8 +350,13 @@ class Follow(StatorModel): # Resolve source and target and see if a Follow exists (it really should) try: follow = cls.by_ap(data["object"]) - except cls.DoesNotExist: - raise ValueError("No Follow locally for incoming Reject", data) + except (cls.DoesNotExist, Identity.DoesNotExist): + capture_message( + "Follow or Identity not found for incoming Reject", + extras={"data": data}, + ) + return + # Ensure the Accept actor is the Follow's target if data["actor"] != follow.target.actor_uri: raise ValueError("Reject actor does not match its Follow object", data) @@ -353,8 +371,12 @@ class Follow(StatorModel): # Resolve source and target and see if a Follow exists (it hopefully does) try: follow = cls.by_ap(data["object"]) - except cls.DoesNotExist: - raise ValueError("No Follow locally for incoming Undo", data) + except (cls.DoesNotExist, Identity.DoesNotExist): + capture_message( + "Follow or Identity not found for incoming Undo", extras={"data": data} + ) + return + # Ensure the Undo actor is the Follow's source if data["actor"] != follow.source.actor_uri: raise ValueError("Accept actor does not match its Follow object", data)