diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index 5e66077c..fa153569 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -1,6 +1,7 @@ """ basics for an activitypub serializer """ from dataclasses import dataclass, fields, MISSING from json import JSONEncoder +import logging from django.apps import apps from django.db import IntegrityError, transaction @@ -8,6 +9,8 @@ from django.db import IntegrityError, transaction from bookwyrm.connectors import ConnectorException, get_data from bookwyrm.tasks import app +logger = logging.getLogger(__name__) + class ActivitySerializerError(ValueError): """routine problems serializing activitypub json""" @@ -268,9 +271,9 @@ def resolve_remote_id( try: data = get_data(remote_id) except ConnectorException: - raise ActivitySerializerError( - f"Could not connect to host for remote_id: {remote_id}" - ) + logger.exception("Could not connect to host for remote_id: %s", remote_id) + return None + # determine the model implicitly, if not provided # or if it's a model with subclasses like Status, check again if not model or hasattr(model.objects, "select_subclasses"): diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index b933edce..1e31de77 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -116,11 +116,8 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): def ignore_activity(cls, activity): # pylint: disable=too-many-return-statements """keep notes if they are replies to existing statuses""" if activity.type == "Announce": - try: - boosted = activitypub.resolve_remote_id( - activity.object, get_activity=True - ) - except activitypub.ActivitySerializerError: + boosted = activitypub.resolve_remote_id(activity.object, get_activity=True) + if not boosted: # if we can't load the status, definitely ignore it return True # keep the boost if we would keep the status diff --git a/bookwyrm/tests/models/test_status_model.py b/bookwyrm/tests/models/test_status_model.py index 837cd41d..2f1e8670 100644 --- a/bookwyrm/tests/models/test_status_model.py +++ b/bookwyrm/tests/models/test_status_model.py @@ -462,6 +462,8 @@ class Status(TestCase): @responses.activate def test_ignore_activity_boost(self, *_): """don't bother with most remote statuses""" + responses.add(responses.GET, "http://fish.com/nothing") + activity = activitypub.Announce( id="http://www.faraway.com/boost/12", actor=self.remote_user.remote_id,