From eaefd631bf87cbdcd209204f36b716285a9c3046 Mon Sep 17 00:00:00 2001 From: Filip Trplan Date: Sun, 29 Sep 2024 10:57:46 +0200 Subject: [PATCH] fix: prevent error when more than two streams with the same hash in set_torrent_rd --- src/controllers/items.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controllers/items.py b/src/controllers/items.py index e4b15790..e213f562 100644 --- a/src/controllers/items.py +++ b/src/controllers/items.py @@ -316,12 +316,13 @@ def set_torrent_rd(request: Request, id: int, torrent_id: str): fetched_torrent_info = torrent_info(torrent_id) - stream = session.execute(select(Stream).where(Stream.infohash == fetched_torrent_info["hash"])).scalar_one_or_none() + stream = session.execute(select(Stream).where(Stream.infohash == fetched_torrent_info["hash"])).scalars().first() hash = fetched_torrent_info["hash"] # Create stream if it doesn't exist if stream is None: stream = create_stream(hash, fetched_torrent_info) + item.streams.append(stream) # check if the stream exists in the item stream_exists_in_item = next((stream for stream in item.streams if stream.infohash == hash), None)