Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: TypeError: '>' not supported between instances of 'NoneType' and 'int'

### INFO
**Python Version**: `3.8.5 (default, Aug  2 2020, 15:09:07) [GCC 9.3.0]`
**Operating System**: `Linux-4.9.35-v7+-armv7l-with-glibc2.29`
**Locale**: `UTF-8`
**Branch**: [develop](../tree/develop)
**Database**: `44.18`
**Commit**: pymedusa/Medusa@6522b5eef4f089d4a4bd0ca463b8828a077b479e
**Link to Log**: https://gist.github.com/86b7a50415672536bed7b6c2e2f92f35
### ERROR
<pre>
2021-03-27 04:29:31 ERROR    DOWNLOADHANDLER :: [6522b5e] Exception while checking torrent status. with error: '>' not supported between instances of 'NoneType' and 'int'
Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/6522b5eef4f089d4a4bd0ca463b8828a077b479e/medusa/schedulers/download_handler.py#L344">medusa/schedulers/download_handler.py</a>", line 344, in run
    self._check_torrent_ratio(torrent_client)
  File "/home/pi/Medusa/<a href="../blob/6522b5eef4f089d4a4bd0ca463b8828a077b479e/medusa/schedulers/download_handler.py#L244">medusa/schedulers/download_handler.py</a>", line 244, in _check_torrent_ratio
    desired_ratio = provider_ratio if provider_ratio > -1 else app.TORRENT_SEED_RATIO
TypeError: '>' not supported between instances of 'NoneType' and 'int'
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:
How to repro this? Judging from the code this should never happen.
Nah, it can happen. When provider.ratio is None. Probably for new providers that haven't been reconfigured. 
It should be `''` for new providers: https://github.com/pymedusa/Medusa/blob/b352bb6924afcdfafce176a540d53ce405ca1312/medusa/server/web/config/providers.py#L401-L406 That's why I'm asking.
Yes I see
The providers are all set as `-1`
Can you check if they are all saved as `-1` in config.ini?
```
limetorrents_ratio = -1
btnext_ratio = -1
filelist_ratio = -1
ptfiles_ratio = -1
xspeeds_ratio = -1
isohunt_ratio = -1
torrentbytes_ratio = -1
pretome_ratio = -1
nebulance_ratio = -1
torrentday_ratio = -1
hdspace_ratio = -1
torrentleech_ratio = -1
alpharatio_ratio = -1
iptorrents_ratio = -1
bithdtv_ratio = -1
torrentseeds_ratio = -1
rarbg_ratio = -1
btn_ratio = -1
acid_lounge_ratio = -1
torrenting_ratio = -1
tvchaosuk_ratio = -1
hdtorrents_ratio = -1
hdme_ratio = -1
zooqle_ratio = -1
uhdbits_ratio = -1
scenetime_ratio = -1
demonoid_ratio = -1
polishsource_ratio = -1
speedcd_ratio = -1
eztv_ratio = -1
beyond_hd_ratio = -1
danishbits_ratio = -1
morethantv_ratio = -1
btdb_ratio = -1
nordicbits_ratio = -1
torrentproject_ratio = -1
btdigg_ratio = -1
torrentz2_ratio = -1
hdbits_ratio = -1
privatehd_ratio = -1
cinemaz_ratio = -1
thepiratebay_ratio = -1
sdbits_ratio = -1
bj_share_ratio = -1
bitcannon_ratio = 1
tokyotoshokan_ratio = -1
animebytes_ratio = -1
xthor_ratio = -1
shazbat_tv_ratio = -1
abnormal_ratio = -1
norbits_ratio = -1
animetorrents_ratio = -1
anidex_ratio = -1
shanaproject_ratio = -1
nyaa_ratio = -1
yggtorrent_ratio = -1
hebits_ratio = -1
elitetracker_ratio = -1
archetorrent_ratio = -1
avistaz_ratio = -1
ncore_ratio = -1
gimmepeers_ratio = -1
torrent_seed_ratio = 2.0
```
I can catch the exeption and log the provider? 
This was likely a one time thing. It can only happen if a provider is added while the DH thread is running.
This happens always that the download checker runs. Just like this log: https://gist.github.com/86b7a50415672536bed7b6c2e2f92f35
Does it still happen if you restart?
Yup, just restarted to check and still and same:
```
2021-03-28 22:05:14 ERROR    DOWNLOADHANDLER :: [4b7db50] Exception while checking torrent status. with error: '>' not supported between instances of 'NoneType' and 'int'
Traceback (most recent call last):
  File "/home/pi/Medusa/medusa/schedulers/download_handler.py", line 344, in run
    self._check_torrent_ratio(torrent_client)
  File "/home/pi/Medusa/medusa/schedulers/download_handler.py", line 244, in _check_torrent_ratio
    desired_ratio = provider_ratio if provider_ratio > -1 else app.TORRENT_SEED_RATIO
TypeError: '>' not supported between instances of 'NoneType' and 'int'
```
I guess we should add a catch at this point as you suggested @p0psicles 

Resolving patch:
diff --git a/medusa/schedulers/download_handler.py b/medusa/schedulers/download_handler.py
--- a/medusa/schedulers/download_handler.py
+++ b/medusa/schedulers/download_handler.py
@@ -241,7 +241,13 @@ def _check_torrent_ratio(self, client):
                 continue
 
             provider_ratio = -1 if provider.ratio == '' else provider.ratio
-            desired_ratio = provider_ratio if provider_ratio > -1 else app.TORRENT_SEED_RATIO
+            try:
+                desired_ratio = provider_ratio if provider_ratio > -1 else app.TORRENT_SEED_RATIO
+            except TypeError:
+                log.warning('could not get provider ratio {ratio} for provider {provider}', {
+                    'ratio': provider_ratio, 'provider': provider_id
+                })
+                desired_ratio = app.TORRENT_SEED_RATIO
 
             if desired_ratio == -1:
                 # Not sure if this option is of use.


Test patch: