From 6cade742f01b4b7413d61d5ff84fcfdb07eb0370 Mon Sep 17 00:00:00 2001 From: mhdzumair Date: Sun, 29 Sep 2024 11:03:13 +0530 Subject: [PATCH] Fix storing episode data with unknown season --- db/crud.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/db/crud.py b/db/crud.py index 2408e31..d2129ac 100644 --- a/db/crud.py +++ b/db/crud.py @@ -398,9 +398,18 @@ async def store_new_torrent_streams( if existing_stream: update_data = {"seeders": stream.seeders, "updated_at": datetime.now()} if stream.season and stream.season.episodes: - existing_episodes = { - ep.episode_number for ep in existing_stream.season.episodes - } + # Check if existing_stream.season exists before accessing its episodes + existing_episodes = set() + if existing_stream.season: + existing_episodes = ( + { + ep.episode_number + for ep in existing_stream.season.episodes + } + if existing_stream.season.episodes + else set() + ) + new_episodes = [ ep for ep in stream.season.episodes @@ -412,9 +421,13 @@ async def store_new_torrent_streams( len(new_episodes), stream.id, ) - update_data["season.episodes"] = ( - existing_stream.season.episodes + new_episodes - ) + if existing_stream.season and existing_stream.season.episodes: + update_data["season.episodes"] = ( + existing_stream.season.episodes + new_episodes + ) + else: + update_data["season"] = stream.season + await existing_stream.update(Set(update_data), bulk_writer=bulk_writer) logging.info("Updated stream %s for %s", stream.id, stream.meta_id) else: