From 2548ba926aaca6be25ae5e26cbe0c55271edfedd Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 13 Mar 2021 07:15:30 -0800 Subject: [PATCH] Fixes error when receiving Undo for unknown boost --- bookwyrm/activitypub/verbs.py | 3 +++ bookwyrm/tests/views/test_inbox.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/bookwyrm/activitypub/verbs.py b/bookwyrm/activitypub/verbs.py index cd7a757b..1788dda7 100644 --- a/bookwyrm/activitypub/verbs.py +++ b/bookwyrm/activitypub/verbs.py @@ -70,6 +70,9 @@ class Undo(Verb): if self.object.type == "Follow": model = apps.get_model("bookwyrm.UserFollows") obj = self.object.to_model(model=model, save=False, allow_create=False) + if not obj: + # if we don't have the object, we can't undo it. happens a lot with boosts + return obj.delete() diff --git a/bookwyrm/tests/views/test_inbox.py b/bookwyrm/tests/views/test_inbox.py index cab50892..d43018db 100644 --- a/bookwyrm/tests/views/test_inbox.py +++ b/bookwyrm/tests/views/test_inbox.py @@ -563,6 +563,23 @@ class Inbox(TestCase): } views.inbox.activity_task(activity) + def test_handle_unboost_unknown_boost(self): + """ undo a boost """ + activity = { + "type": "Undo", + "actor": "hi", + "id": "bleh", + "to": ["https://www.w3.org/ns/activitystreams#public"], + "cc": ["https://example.com/user/mouse/followers"], + "object": { + "type": "Announce", + "id": "http://fake.com/unknown/boost", + "actor": self.remote_user.remote_id, + "object": self.status.remote_id, + }, + } + views.inbox.activity_task(activity) + def test_handle_add_book_to_shelf(self): """ shelving a book """ work = models.Work.objects.create(title="work title")