Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: KeyError: 'backlog_search'

### INFO
**Python Version**: `3.7.5 (default, Nov  1 2019, 02:16:23) [Clang 11.0.0 (clang-1100.0.33.8)]`
**Operating System**: `Darwin-19.0.0-x86_64-i386-64bit`
**Locale**: `UTF-8`
**Branch**: [master](../tree/master)
**Database**: `44.14`
**Commit**: pymedusa/Medusa@fcb5a1969dcd4ea0b6fb4a9debbf60179b0bbf4b
**Link to Log**: https://gist.github.com/eb1b2912f593d5e8574e1b984384246e
### ERROR
<pre>
2019-12-05 17:41:37 ERROR    Thread_19 :: [fcb5a19] Exception generated: 'backlog_search'
Traceback (most recent call last):
  File "/Users/ovidijus/Apps/Medusa/<a href="../blob/fcb5a1969dcd4ea0b6fb4a9debbf60179b0bbf4b/medusa/server/web/core/base.py#L251">medusa/server/web/core/base.py</a>", line 251, in async_call
    result = function(**kwargs)
  File "/Users/ovidijus/Apps/Medusa/<a href="../blob/fcb5a1969dcd4ea0b6fb4a9debbf60179b0bbf4b/medusa/server/web/manage/searches.py#L26">medusa/server/web/manage/searches.py</a>", line 26, in index
    forcedSearchQueueLength=app.forced_search_queue_scheduler.action.queue_length(),
  File "/Users/ovidijus/Apps/Medusa/<a href="../blob/fcb5a1969dcd4ea0b6fb4a9debbf60179b0bbf4b/medusa/search/queue.py#L179">medusa/search/queue.py</a>", line 179, in queue_length
    length['backlog_search'] += 1
KeyError: 'backlog_search'
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:

### INFO
**Python Version**: `3.7.5 (default, Nov  1 2019, 02:16:23) [Clang 11.0.0 (clang-1100.0.33.8)]`
**Operating System**: `Darwin-19.0.0-x86_64-i386-64bit`
**Locale**: `UTF-8`
**Branch**: [master](../tree/master)
**Database**: `44.14`
**Commit**: pymedusa/Medusa@fcb5a1969dcd4ea0b6fb4a9debbf60179b0bbf4b
**Link to Log**: https://gist.github.com/0fd924dec748a93ef3584e18e4b6627b
### ERROR
<pre>
2019-12-05 17:43:41 ERROR    Thread_24 :: [fcb5a19] Exception generated: 'backlog_search'
Traceback (most recent call last):
  File "/Users/ovidijus/Apps/Medusa/<a href="../blob/fcb5a1969dcd4ea0b6fb4a9debbf60179b0bbf4b/medusa/server/web/core/base.py#L251">medusa/server/web/core/base.py</a>", line 251, in async_call
    result = function(**kwargs)
  File "/Users/ovidijus/Apps/Medusa/<a href="../blob/fcb5a1969dcd4ea0b6fb4a9debbf60179b0bbf4b/medusa/server/web/manage/searches.py#L26">medusa/server/web/manage/searches.py</a>", line 26, in index
    forcedSearchQueueLength=app.forced_search_queue_scheduler.action.queue_length(),
  File "/Users/ovidijus/Apps/Medusa/<a href="../blob/fcb5a1969dcd4ea0b6fb4a9debbf60179b0bbf4b/medusa/search/queue.py#L179">medusa/search/queue.py</a>", line 179, in queue_length
    length['backlog_search'] += 1
KeyError: 'backlog_search'
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators

this happens when i try to go to Manage Searches page when there was something in the backlog.. disappointing that this is broken on master.

this breaks as soon as there is 2 or more items in the backlog.

### INFO
**Python Version**: `3.7.5 (default, Nov  1 2019, 02:16:23) [Clang 11.0.0 (clang-1100.0.33.8)]`
**Operating System**: `Darwin-19.0.0-x86_64-i386-64bit`
**Locale**: `UTF-8`
**Branch**: [develop](../tree/develop)
**Database**: `44.14`
**Commit**: pymedusa/Medusa@6456664611d1fe304d7e3118104dcac4cd607a25
**Link to Log**: https://gist.github.com/b1954bb9315bc610b131017c85de575d
### ERROR
<pre>
2019-12-05 17:49:48 ERROR    Thread_0 :: [6456664] Exception generated: 'backlog_search'
Traceback (most recent call last):
  File "/Users/ovidijus/Apps/Medusa/<a href="../blob/6456664611d1fe304d7e3118104dcac4cd607a25/medusa/server/web/core/base.py#L251">medusa/server/web/core/base.py</a>", line 251, in async_call
    result = function(**kwargs)
  File "/Users/ovidijus/Apps/Medusa/<a href="../blob/6456664611d1fe304d7e3118104dcac4cd607a25/medusa/server/web/manage/searches.py#L26">medusa/server/web/manage/searches.py</a>", line 26, in index
    forcedSearchQueueLength=app.forced_search_queue_scheduler.action.queue_length(),
  File "/Users/ovidijus/Apps/Medusa/<a href="../blob/6456664611d1fe304d7e3118104dcac4cd607a25/medusa/search/queue.py#L179">medusa/search/queue.py</a>", line 179, in queue_length
    length['backlog_search'] += 1
KeyError: 'backlog_search'
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators

seems to be broken on develop branch as well..

To Reproduce:
have 2 episodes from different shows marked as snatched but never downloaded
then retry download, select no when the popup shows.
do this on 2 or more episodes to queue up in backlog, then go to Manage Searches, white page will only display & error in log.
Report once and wait for the fix. Avoid useless comments that waste our time.
tnx @XxUnkn0wnxX i'll look into it. Pls standby for testing out a fix when ready. Don't know when, as I have to also look into the show updater issues

Resolving patch:
diff --git a/medusa/search/queue.py b/medusa/search/queue.py
--- a/medusa/search/queue.py
+++ b/medusa/search/queue.py
@@ -169,7 +169,7 @@ def is_forced_search_in_progress(self):
 
     def queue_length(self):
         """Get queue length."""
-        length = {'forced_search': 0, 'manual_search': 0, 'failed': 0}
+        length = {'backlog_search': 0, 'manual_search': 0, 'failed': 0}
         for cur_item in self.queue:
             if isinstance(cur_item, FailedQueueItem):
                 length['failed'] += 1


Test patch: