Skip to content

Commit

Permalink
Protocol.receive: on a delete for an object we don't have, don't writ…
Browse files Browse the repository at this point in the history
…e the object

for #1149
  • Loading branch information
snarfed committed Jan 14, 2025
1 parent 1a985ad commit 3a884a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
8 changes: 7 additions & 1 deletion protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion tests/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 3a884a2

Please sign in to comment.