From 8cf02e31c94a48482c48e7295d574856d2168ac0 Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Thu, 3 Jun 2021 06:44:38 -0400 Subject: [PATCH] Fixed delete query that could delete a series improperly on any http error returned by Sonarr API. --- bazarr/get_series.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bazarr/get_series.py b/bazarr/get_series.py index 4f1417734..42a5d6972 100644 --- a/bazarr/get_series.py +++ b/bazarr/get_series.py @@ -147,6 +147,13 @@ def update_one_series(series_id, action): except DoesNotExist: existing_series = None + # Delete series from DB + if action == 'deleted' and existing_series: + TableShows.delete().where(TableShows.sonarrSeriesId == int(series_id)).execute() + TableEpisodes.delete().where(TableEpisodes.sonarrSeriesId == int(series_id)).execute() + event_stream(type='series', action='delete', payload=int(series_id)) + return + sonarr_version = get_sonarr_version() serie_default_enabled = settings.general.getboolean('serie_default_enabled') @@ -164,15 +171,8 @@ def update_one_series(series_id, action): # Get series data from sonarr api series = None - try: - series_data = get_series_from_sonarr_api(url=url_sonarr(), apikey_sonarr=settings.sonarr.apikey, - sonarr_series_id=int(series_id)) - except requests.exceptions.HTTPError: - # Series has been deleted - TableShows.delete().where(TableShows.sonarrSeriesId == int(series_id)).execute() - TableEpisodes.delete().where(TableEpisodes.sonarrSeriesId == int(series_id)).execute() - event_stream(type='series', action='delete', payload=int(series_id)) - return + series_data = get_series_from_sonarr_api(url=url_sonarr(), apikey_sonarr=settings.sonarr.apikey, + sonarr_series_id=int(series_id)) if not series_data: return