diff --git a/swh/indexer/origin_head.py b/swh/indexer/origin_head.py --- a/swh/indexer/origin_head.py +++ b/swh/indexer/origin_head.py @@ -124,8 +124,13 @@ def _try_resolve_target(self, branches, target_name): try: target = branches[target_name] + if target is None: + return None while target['target_type'] == 'alias': target = branches[target['target']] + if target is None: + return None + if target['target_type'] == 'revision': return target['target'] elif target['target_type'] == 'content': diff --git a/swh/indexer/tests/test_origin_head.py b/swh/indexer/tests/test_origin_head.py --- a/swh/indexer/tests/test_origin_head.py +++ b/swh/indexer/tests/test_origin_head.py @@ -65,6 +65,26 @@ ['git+https://github.com/SoftwareHeritage/swh-indexer']) self.assertEqual(self.indexer.results, []) + def test_pypi_missing_branch(self): + origin_id = self.indexer.storage.origin_add_one({ + 'type': 'pypi', + 'url': 'https://pypi.org/project/abcdef/', + }) + visit = self.indexer.storage.origin_visit_add( + origin_id, '2019-02-27') + self.indexer.storage.snapshot_add(origin_id, visit['visit'], { + 'id': 'foo', + 'branches': { + b'foo': None, + b'HEAD': { + 'target_type': 'alias', + 'target': b'foo', + } + } + }) + self.indexer.run(['pypi+https://pypi.org/project/abcdef/']) + self.assertEqual(self.indexer.results, []) + def test_ftp(self): self.indexer.run( ['ftp+rsync://ftp.gnu.org/gnu/3dldf'])