Skip to content

Commit

Permalink
fix: prevent error when more than two streams with the same hash in s…
Browse files Browse the repository at this point in the history
…et_torrent_rd
  • Loading branch information
filiptrplan authored and dreulavelle committed Sep 29, 2024
1 parent afc58b8 commit eaefd63
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/controllers/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit eaefd63

Please sign in to comment.