Fixes error when receiving Undo for unknown boost

This commit is contained in:
Mouse Reeve 2021-03-13 07:15:30 -08:00
parent 848edd2972
commit 2548ba926a
2 changed files with 20 additions and 0 deletions

View file

@ -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()

View file

@ -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")