From 3a884a2c4e2ce62cbbde961522b9f89a2baad503 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Mon, 13 Jan 2025 20:51:17 -0800 Subject: [PATCH] Protocol.receive: on a delete for an object we don't have, don't write the object for #1149 --- protocol.py | 8 +++++++- tests/test_protocol.py | 9 +-------- tests/test_web.py | 4 +++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/protocol.py b/protocol.py index 953aac01..f14ae4b7 100644 --- a/protocol.py +++ b/protocol.py @@ -966,8 +966,14 @@ def receive(from_cls, obj, authed_as=None, internal=False, received_at=None): elif obj.type in ('delete', 'undo'): assert inner_obj_id + inner_obj = Object.get_by_id(inner_obj_id, authed_as=authed_as) + if not inner_obj: + logger.info(f"Ignoring, we don't have {inner_obj_id} stored") + return 'OK', 204 + logger.info(f'Marking Object {inner_obj_id} deleted') - Object.get_or_create(inner_obj_id, deleted=True, authed_as=authed_as) + inner_obj.deleted = True + inner_obj.put() # if this is an actor, handle deleting it later so that # in case it's from_user, user.enabled_protocols is still populated diff --git a/tests/test_protocol.py b/tests/test_protocol.py index 8f2a4a5b..4d4197cb 100644 --- a/tests/test_protocol.py +++ b/tests/test_protocol.py @@ -2046,8 +2046,6 @@ def test_delete_doesnt_fetch_author(self): _, status = Fake.receive_as1(delete_as1, authed_as='fake:user') self.assertEqual(204, status) - self.assert_object('fake:post', source_protocol=None, deleted=True) - obj = self.assert_object('fake:delete', our_as1=delete_as1, type='delete', @@ -2066,12 +2064,7 @@ def test_delete_no_followers_no_stored_object(self): _, code = Fake.receive_as1(delete_as1) self.assertEqual(204, code) - self.assert_object('fake:post', - deleted=True, - source_protocol=None, - feed=[], - ) - + self.assertIsNone(Object.get_by_id('fake:post')) self.assert_object('fake:delete', our_as1=delete_as1, type='delete', diff --git a/tests/test_web.py b/tests/test_web.py index e37b6fd3..cee5583e 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -1634,7 +1634,9 @@ def test_delete(self, mock_get, mock_post): mock_get.return_value = requests_response('"unused"', status=410, url='http://final/delete') mock_post.return_value = requests_response('unused', status=200) - Object(id='https://user.com/post#bridgy-fed-create', mf2=NOTE_MF2).put() + + Object(id='https://user.com/post', mf2=NOTE_MF2, source_protocol='web').put() + Object(id='https://user.com/post#bridgy-fed-create', our_as1=CREATE_AS1).put() self.make_followers()