kopia lustrzana https://github.com/snarfed/bridgy-fed
Protocol.for_id: handle null Object.source_protocol
rodzic
65e1479d88
commit
bfb462e414
|
@ -175,8 +175,9 @@ class Protocol:
|
|||
logger.info(f'Trying {protocol.__name__}')
|
||||
try:
|
||||
obj = protocol.load(id)
|
||||
logger.info(f"Looks like it's {obj.source_protocol}")
|
||||
return PROTOCOLS[obj.source_protocol]
|
||||
if obj.source_protocol:
|
||||
logger.info(f"{obj.key} has source_protocol {obj.source_protocol}")
|
||||
return PROTOCOLS[obj.source_protocol]
|
||||
except werkzeug.exceptions.HTTPException:
|
||||
# internal error we generated ourselves; try next protocol
|
||||
pass
|
||||
|
@ -185,7 +186,7 @@ class Protocol:
|
|||
if code:
|
||||
# we tried and failed fetching the id over the network
|
||||
return None
|
||||
logger.info(e)
|
||||
raise
|
||||
|
||||
logger.info(f'No matching protocol found for {id} !')
|
||||
return None
|
||||
|
|
|
@ -131,6 +131,10 @@ class ProtocolTest(TestCase):
|
|||
Object(id='http://ui/obj', source_protocol='ui').put()
|
||||
self.assertEqual(UIProtocol, Protocol.for_id('http://ui/obj'))
|
||||
|
||||
def test_for_id_object_missing_source_protocol(self):
|
||||
Object(id='http://bad/obj').put()
|
||||
self.assertIsNone(Protocol.for_id('http://bad/obj'))
|
||||
|
||||
@patch('requests.get')
|
||||
def test_for_id_activitypub_fetch(self, mock_get):
|
||||
mock_get.return_value = self.as2_resp(ACTOR)
|
||||
|
|
Ładowanie…
Reference in New Issue