diff --git a/swh/web/common/service.py b/swh/web/common/service.py --- a/swh/web/common/service.py +++ b/swh/web/common/service.py @@ -279,11 +279,9 @@ for match in matches: match['from_revision'] = hashutil.hash_to_hex(match['from_revision']) + origin = None if match['origin_url']: origin = storage.origin_get({'url': match['origin_url']}) - else: - # Fallback to origin-id for idx-storage with outdated db - origin = storage.origin_get({'id': match['id']}) del match['origin_url'] if 'id' in match: diff --git a/swh/web/tests/api/views/test_origin.py b/swh/web/tests/api/views/test_origin.py --- a/swh/web/tests/api/views/test_origin.py +++ b/swh/web/tests/api/views/test_origin.py @@ -634,3 +634,33 @@ self.assertEqual(rv.status_code, 400, rv.content) mock_idx_storage.assert_not_called() + + def test_api_origin_metadata_search_missing_origin_url(self): + with patch('swh.web.common.service.idx_storage') as mock_idx_storage: + mock_idx_storage.origin_intrinsic_metadata_search_fulltext \ + .side_effect = lambda conjunction, limit: [{ + 'from_revision': ( + b'p&\xb7\xc1\xa2\xafVR\x1e\x95\x1c\x01\xed ' + b'\xf2U\xfa\x05B8'), + 'metadata': {'author': 'Jane Doe'}, + 'origin_url': None, + 'tool': { + 'configuration': { + 'context': ['NpmMapping', 'CodemetaMapping'], + 'type': 'local' + }, + 'id': 3, + 'name': 'swh-metadata-detector', + 'version': '0.0.1' + } + }] + + url = reverse('api-1-origin-metadata-search', + query_params={'fulltext': 'Jane Doe'}) + rv = self.client.get(url) + + self.assertEqual(rv.status_code, 200, rv.content) + self.assertEqual(rv['Content-Type'], 'application/json') + self.assertEqual(len(rv.data), 0) + mock_idx_storage.origin_intrinsic_metadata_search_fulltext \ + .assert_called_with(conjunction=['Jane Doe'], limit=70)