diff --git a/swh/storage/in_memory.py b/swh/storage/in_memory.py --- a/swh/storage/in_memory.py +++ b/swh/storage/in_memory.py @@ -289,8 +289,10 @@ hash = content.get(algo) if hash and hash in self._content_indexes[algo]: found.append(self._content_indexes[algo][hash]) + if not found: - return + return [] + keys = list(set.intersection(*found)) return copy.deepcopy([self._contents[key] for key in keys]) diff --git a/swh/storage/storage.py b/swh/storage/storage.py --- a/swh/storage/storage.py +++ b/swh/storage/storage.py @@ -516,12 +516,8 @@ sha256=content.get('sha256'), blake2s256=content.get('blake2s256'), cur=cur) - if contents: - contents_list = [] - for cont in contents: - contents_list.append(dict(zip(db.content_find_cols, cont))) - return contents_list - return None + return [dict(zip(db.content_find_cols, content)) + for content in contents] @db_transaction() def directory_add(self, directories, db, cur): diff --git a/swh/storage/tests/test_storage.py b/swh/storage/tests/test_storage.py --- a/swh/storage/tests/test_storage.py +++ b/swh/storage/tests/test_storage.py @@ -2494,19 +2494,19 @@ actually_present = self.storage.content_find( {'sha1': missing_cont['sha1']}) - self.assertIsNone(actually_present) + self.assertEqual(actually_present, []) # 2. with something that does not exist actually_present = self.storage.content_find( {'sha1_git': missing_cont['sha1_git']}) - self.assertIsNone(actually_present) + self.assertEqual(actually_present, []) # 3. with something that does not exist actually_present = self.storage.content_find( {'sha256': missing_cont['sha256']}) - self.assertIsNone(actually_present) + self.assertEqual(actually_present, []) def test_content_find_with_duplicate_input(self): cont1 = self.cont