forked from mirrors/bookwyrm
Merge pull request #2133 from bookwyrm-social/activitypub-connection-erorr
Don't throw an error when unable to connect to remote data
This commit is contained in:
commit
77a7dfa924
3 changed files with 10 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
||||||
""" basics for an activitypub serializer """
|
""" basics for an activitypub serializer """
|
||||||
from dataclasses import dataclass, fields, MISSING
|
from dataclasses import dataclass, fields, MISSING
|
||||||
from json import JSONEncoder
|
from json import JSONEncoder
|
||||||
|
import logging
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.db import IntegrityError, transaction
|
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.connectors import ConnectorException, get_data
|
||||||
from bookwyrm.tasks import app
|
from bookwyrm.tasks import app
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ActivitySerializerError(ValueError):
|
class ActivitySerializerError(ValueError):
|
||||||
"""routine problems serializing activitypub json"""
|
"""routine problems serializing activitypub json"""
|
||||||
|
@ -268,9 +271,9 @@ def resolve_remote_id(
|
||||||
try:
|
try:
|
||||||
data = get_data(remote_id)
|
data = get_data(remote_id)
|
||||||
except ConnectorException:
|
except ConnectorException:
|
||||||
raise ActivitySerializerError(
|
logger.exception("Could not connect to host for remote_id: %s", remote_id)
|
||||||
f"Could not connect to host for remote_id: {remote_id}"
|
return None
|
||||||
)
|
|
||||||
# determine the model implicitly, if not provided
|
# determine the model implicitly, if not provided
|
||||||
# or if it's a model with subclasses like Status, check again
|
# or if it's a model with subclasses like Status, check again
|
||||||
if not model or hasattr(model.objects, "select_subclasses"):
|
if not model or hasattr(model.objects, "select_subclasses"):
|
||||||
|
|
|
@ -116,11 +116,8 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||||
def ignore_activity(cls, activity): # pylint: disable=too-many-return-statements
|
def ignore_activity(cls, activity): # pylint: disable=too-many-return-statements
|
||||||
"""keep notes if they are replies to existing statuses"""
|
"""keep notes if they are replies to existing statuses"""
|
||||||
if activity.type == "Announce":
|
if activity.type == "Announce":
|
||||||
try:
|
boosted = activitypub.resolve_remote_id(activity.object, get_activity=True)
|
||||||
boosted = activitypub.resolve_remote_id(
|
if not boosted:
|
||||||
activity.object, get_activity=True
|
|
||||||
)
|
|
||||||
except activitypub.ActivitySerializerError:
|
|
||||||
# if we can't load the status, definitely ignore it
|
# if we can't load the status, definitely ignore it
|
||||||
return True
|
return True
|
||||||
# keep the boost if we would keep the status
|
# keep the boost if we would keep the status
|
||||||
|
|
|
@ -462,6 +462,8 @@ class Status(TestCase):
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_ignore_activity_boost(self, *_):
|
def test_ignore_activity_boost(self, *_):
|
||||||
"""don't bother with most remote statuses"""
|
"""don't bother with most remote statuses"""
|
||||||
|
responses.add(responses.GET, "http://fish.com/nothing")
|
||||||
|
|
||||||
activity = activitypub.Announce(
|
activity = activitypub.Announce(
|
||||||
id="http://www.faraway.com/boost/12",
|
id="http://www.faraway.com/boost/12",
|
||||||
actor=self.remote_user.remote_id,
|
actor=self.remote_user.remote_id,
|
||||||
|
|
Loading…
Reference in a new issue