From 0bfe1e9dfc0934b5c6d929cc056f86e70cced74b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 25 May 2022 13:24:11 -0700 Subject: [PATCH 1/3] Don't throw an error when unable to connect to remote data --- bookwyrm/activitypub/base_activity.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index 448d5563..58c59e5b 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,11 @@ 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"): From 3e54a5f4a3f974133b1020c34504b1fb62cc9a5d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 26 May 2022 09:00:45 -0700 Subject: [PATCH 2/3] Python formatting --- bookwyrm/activitypub/base_activity.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index 58c59e5b..63ec2d01 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -271,9 +271,7 @@ def resolve_remote_id( try: data = get_data(remote_id) except ConnectorException: - logger.exception( - "Could not connect to host for remote_id: %s", remote_id - ) + logger.exception("Could not connect to host for remote_id: %s", remote_id) return None # determine the model implicitly, if not provided From 9d275db3227145271696fff26add7c6f4c792b88 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 26 May 2022 09:57:39 -0700 Subject: [PATCH 3/3] Updates ignore boost logic that no longer produces errors --- bookwyrm/models/status.py | 7 ++----- bookwyrm/tests/models/test_status_model.py | 2 ++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 17fcd458..45e2cbae 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,