From 4c2bc381fe2762e07ea85ee8aea93be4ee53994f Mon Sep 17 00:00:00 2001 From: Egbert Bouman Date: Fri, 14 Jun 2024 12:52:32 +0200 Subject: [PATCH] Fix error in TorrentInfoEndpoint --- src/tribler/core/libtorrent/restapi/torrentinfo_endpoint.py | 5 +++-- .../core/libtorrent/restapi/test_torrentinfo_endpoint.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tribler/core/libtorrent/restapi/torrentinfo_endpoint.py b/src/tribler/core/libtorrent/restapi/torrentinfo_endpoint.py index f6fdd20975a..1567880c03a 100644 --- a/src/tribler/core/libtorrent/restapi/torrentinfo_endpoint.py +++ b/src/tribler/core/libtorrent/restapi/torrentinfo_endpoint.py @@ -207,8 +207,9 @@ async def get_torrent_info(self, request: Request) -> RESTResponse: # noqa: C90 self.download_manager.notifier.notify(Notification.torrent_metadata_added, metadata=metadata_dict) download = self.download_manager.downloads.get(metadata_dict["infohash"]) - metainfo_request = self.download_manager.metainfo_requests.get(metadata_dict["infohash"], [None])[0] - download_is_metainfo_request = download == metainfo_request + metainfo_lookup = self.download_manager.metainfo_requests.get(metadata_dict["infohash"]) + metainfo_download = metainfo_lookup.download if metainfo_lookup else None + download_is_metainfo_request = download == metainfo_download # Check if the torrent is already in the downloads encoded_metainfo = deepcopy(metainfo) diff --git a/src/tribler/test_unit/core/libtorrent/restapi/test_torrentinfo_endpoint.py b/src/tribler/test_unit/core/libtorrent/restapi/test_torrentinfo_endpoint.py index 8050ee21e3b..c4b224da807 100644 --- a/src/tribler/test_unit/core/libtorrent/restapi/test_torrentinfo_endpoint.py +++ b/src/tribler/test_unit/core/libtorrent/restapi/test_torrentinfo_endpoint.py @@ -8,6 +8,7 @@ from ipv8.test.base import TestBase import tribler +from tribler.core.libtorrent.download_manager.download_manager import MetainfoLookup from tribler.core.libtorrent.restapi.torrentinfo_endpoint import TorrentInfoEndpoint, recursive_unicode from tribler.core.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo from tribler.core.restapi.rest_endpoint import HTTP_BAD_REQUEST, HTTP_INTERNAL_SERVER_ERROR @@ -479,7 +480,8 @@ async def test_get_torrent_info_valid_metainfo_request(self) -> None: Test if a valid metainfo request has its info returned correctly. """ tdef = TorrentDef().load_from_memory(TORRENT_WITH_DIRS_CONTENT) - self.download_manager.metainfo_requests = {tdef.infohash: [self.download_manager.downloads.get(tdef.infohash)]} + download = self.download_manager.downloads.get(tdef.infohash) + self.download_manager.metainfo_requests = {tdef.infohash: MetainfoLookup(download, 1)} with patch("tribler.core.libtorrent.torrentdef.TorrentDef.load", AsyncMock(return_value=tdef)): response = await self.endpoint.get_torrent_info(GetTorrentInfoRequest({"hops": 0, "uri": "file://"})) response_body_json = await response_to_json(response)