From fd3cb71c79d33315e38c7e8c5634a452ad64af29 Mon Sep 17 00:00:00 2001 From: Egbert Bouman Date: Tue, 10 Dec 2024 13:20:22 +0100 Subject: [PATCH] Fix for adding FFA torrents with trackers --- .../core/database/orm_bindings/torrent_metadata.py | 2 ++ src/tribler/test_unit/core/database/test_store.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/tribler/core/database/orm_bindings/torrent_metadata.py b/src/tribler/core/database/orm_bindings/torrent_metadata.py index a304bd6d04..938a8a5050 100644 --- a/src/tribler/core/database/orm_bindings/torrent_metadata.py +++ b/src/tribler/core/database/orm_bindings/torrent_metadata.py @@ -277,6 +277,8 @@ def add_ffa_from_dict(cls: type[Self], metadata: dict) -> Self | None: pk_blob = b"" if cls.exists(lambda g: (g.infohash == ih_blob) or (g.id_ == id_ and g.public_key == pk_blob)): return None + if isinstance(metadata.get("tracker_info", ""), bytes): + metadata["tracker_info"] = metadata["tracker_info"].decode() # Add the torrent as a free-for-all entry if it is unknown to GigaChannel return cls.from_dict(dict(metadata, public_key=b'', status=COMMITTED, id_=id_)) diff --git a/src/tribler/test_unit/core/database/test_store.py b/src/tribler/test_unit/core/database/test_store.py index edc702504b..c6d7819383 100644 --- a/src/tribler/test_unit/core/database/test_store.py +++ b/src/tribler/test_unit/core/database/test_store.py @@ -197,6 +197,15 @@ def test_process_payload_ffa(self) -> None: self.assertIsNotNone(self.metadata_store.TorrentMetadata.get(title=ffa_title)) self.assertEqual([], self.metadata_store.process_payload(ffa_payload)) + @db_session + def test_ffa_with_tracker_info(self) -> None: + """ + Test if FFA entries are correctly added when they have tracker_info. + """ + self.metadata_store.TorrentMetadata.add_ffa_from_dict({"infohash": b"1" * 20, + "title": "abcabc", + "tracker_info": b"http://tracker/announce"}) + @db_session def test_get_entries_query_sort_by_size(self) -> None: """