diff --git a/swh/indexer/storage/__init__.py b/swh/indexer/storage/__init__.py --- a/swh/indexer/storage/__init__.py +++ b/swh/indexer/storage/__init__.py @@ -442,7 +442,7 @@ yield converters.db_to_ctags(dict(zip(db.content_ctags_cols, obj))) @remote_api_endpoint('content/fossology_license') - @db_transaction_generator() + @db_transaction() def content_fossology_license_get(self, ids, db=None, cur=None): """Retrieve licenses per id. @@ -450,8 +450,8 @@ ids (iterable): sha1 checksums Yields: - dict: ``{id: facts}`` where ``facts`` is a dict with the - following keys: + dict: ``{id: facts}`` where ``facts`` is a list of + dicts with the following keys: - **licenses** ([str]): associated licenses for that content - **tool** (dict): Tool used to compute the license @@ -464,8 +464,7 @@ id_ = license['id'] d[id_].append(converters.db_to_fossology_license(license)) - for id_, facts in d.items(): - yield {id_: facts} + return d @remote_api_endpoint('content/fossology_license/add') @db_transaction() diff --git a/swh/indexer/storage/in_memory.py b/swh/indexer/storage/in_memory.py --- a/swh/indexer/storage/in_memory.py +++ b/swh/indexer/storage/in_memory.py @@ -435,11 +435,10 @@ # the new one. SubStorage.get should be updated once all other # *_get methods use the new format. # See: https://forge.softwareheritage.org/T1433 - res = {} + res = defaultdict(list) for d in self._licenses.get(ids): - res.setdefault(d.pop('id'), []).append(d) - for (id_, facts) in res.items(): - yield {id_: facts} + res[d.pop('id')].append(d) + return res def content_fossology_license_add(self, licenses, conflict_update=False): """Add licenses not present in storage. diff --git a/swh/indexer/tests/storage/test_storage.py b/swh/indexer/tests/storage/test_storage.py --- a/swh/indexer/tests/storage/test_storage.py +++ b/swh/indexer/tests/storage/test_storage.py @@ -884,8 +884,8 @@ self.storage.content_fossology_license_add([license_v1]) # when - actual_licenses = list(self.storage.content_fossology_license_get( - [self.sha1_1])) + actual_licenses = self.storage.content_fossology_license_get( + [self.sha1_1]) # then expected_license = { @@ -904,8 +904,8 @@ self.storage.content_fossology_license_add([license_v2]) - actual_licenses = list(self.storage.content_fossology_license_get( - [self.sha1_1])) + actual_licenses = self.storage.content_fossology_license_get( + [self.sha1_1]) expected_license = { self.sha1_1: [{