[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
This commit is contained in:
DjLegolas 2022-01-21 02:40:08 +02:00 committed by Calum Lind
parent a954348567
commit 7fa0af3446
No known key found for this signature in database
GPG Key ID: 90597A687B836BA3
1 changed files with 11 additions and 5 deletions

View File

@ -145,11 +145,17 @@ class SessionProxy(component.Component):
def on_status(result, torrent_id): def on_status(result, torrent_id):
t = time() t = time()
try:
self.torrents[torrent_id][0] = t self.torrents[torrent_id][0] = t
self.torrents[torrent_id][1].update(result) self.torrents[torrent_id][1].update(result)
for key in keys_to_get: for key in keys_to_get:
self.cache_times[torrent_id][key] = t self.cache_times[torrent_id][key] = t
return self.create_status_dict([torrent_id], keys)[torrent_id] 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) return d.addCallback(on_status, torrent_id)
else: else: