From a10e5dbf3778d9aa177f978fc85184d95b1446a0 Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Sat, 18 Nov 2023 14:26:13 -0500 Subject: [PATCH] Fixed `(sqlite3.OperationalError) too many SQL variables issue` while inserting too many episodes at the same time. --- bazarr/sonarr/sync/episodes.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/bazarr/sonarr/sync/episodes.py b/bazarr/sonarr/sync/episodes.py index ded02b7d8..2b9f62981 100644 --- a/bazarr/sonarr/sync/episodes.py +++ b/bazarr/sonarr/sync/episodes.py @@ -94,12 +94,14 @@ def sync_episodes(series_id, send_event=True): # Update existing episodes in DB if len(episodes_to_update): - try: - database.execute(update(TableEpisodes), episodes_to_update) - except IntegrityError as e: - logging.error(f"BAZARR cannot update episodes because of {e}") - else: - for updated_episode in episodes_to_update: + for updated_episode in episodes_to_update: + try: + database.execute(update(TableEpisodes) + .values(updated_episode) + .where(TableEpisodes.sonarrEpisodeId == updated_episode['sonarrEpisodeId'])) + except IntegrityError as e: + logging.error(f"BAZARR cannot update episodes because of {e}") + else: store_subtitles(updated_episode['path'], path_mappings.path_replace(updated_episode['path'])) if send_event: @@ -107,12 +109,12 @@ def sync_episodes(series_id, send_event=True): # Insert new episodes in DB if len(episodes_to_add): - try: - database.execute(insert(TableEpisodes).values(episodes_to_add)) - except IntegrityError as e: - logging.error(f"BAZARR cannot insert episodes because of {e}") - else: - for added_episode in episodes_to_add: + for added_episode in episodes_to_add: + try: + database.execute(insert(TableEpisodes).values(added_episode)) + except IntegrityError as e: + logging.error(f"BAZARR cannot insert episodes because of {e}") + else: store_subtitles(added_episode['path'], path_mappings.path_replace(added_episode['path'])) if send_event: