From 7fa0af344618aee141951d7541d14097460d00b5 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Fri, 21 Jan 2022 02:40:08 +0200 Subject: [PATCH] [Core] Fixed KeyError in sessionproxy after torrent delete When several torrents are being removed from session, an exception was being raised in a callback function `on_status` with the `torrent_id` of one (or more) of the removed torrents. Now we will catch when the torrent does not exist anymore and print a debug log about it. Closes: https://dev.deluge-torrent.org/ticket/3498 Closes: https://github.com/deluge-torrent/deluge/pull/341 --- deluge/ui/sessionproxy.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/deluge/ui/sessionproxy.py b/deluge/ui/sessionproxy.py index a79144e0c..b50ba6c3d 100644 --- a/deluge/ui/sessionproxy.py +++ b/deluge/ui/sessionproxy.py @@ -145,11 +145,17 @@ class SessionProxy(component.Component): def on_status(result, torrent_id): t = time() - self.torrents[torrent_id][0] = t - self.torrents[torrent_id][1].update(result) - for key in keys_to_get: - self.cache_times[torrent_id][key] = t - return self.create_status_dict([torrent_id], keys)[torrent_id] + try: + self.torrents[torrent_id][0] = t + self.torrents[torrent_id][1].update(result) + for key in keys_to_get: + self.cache_times[torrent_id][key] = t + return self.create_status_dict([torrent_id], keys)[torrent_id] + except KeyError: + log.debug( + f'Status missing for torrent (removed?): {torrent_id}' + ) + return {} return d.addCallback(on_status, torrent_id) else: