Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: TypeError: 'NoneType' object is not iterable
### INFO
**Python Version**: `2.7.9 (default, Sep 17 2016, 20:26:04) [GCC 4.9.2]`
**Operating System**: `Linux-4.4.38-v7+-armv7l-with-debian-8.0`
**Locale**: `UTF-8`
**Branch**: [develop](../tree/develop)
**Database**: `44.5`
**Commit**: pymedusa/Medusa@a70a6df42ec915a51409a059df3a58f56c1b2bd7
**Link to Log**: https://gist.github.com/839dc72eb02a30a96952cd7150164207
### ERROR
<pre>
2017-03-17 02:01:22 ERROR    SHOWUPDATER :: [a70a6df] Problem running show_updater, Indexer TVDBv2 seems to be having issues while trying to get updates for show Hannibal. Cause: 'NoneType' object is not iterable.
Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/a70a6df42ec915a51409a059df3a58f56c1b2bd7/medusa/show_updater.py#L86">medusa/show_updater.py</a>", line 86, in run
    update_max_weeks)
  File "/home/pi/Medusa/<a href="../blob/a70a6df42ec915a51409a059df3a58f56c1b2bd7/medusa/indexers/tvdbv2/tvdbv2_api.py#L565">medusa/indexers/tvdbv2/tvdbv2_api.py</a>", line 565, in get_last_updated_series
    last_update_ts = max(x.last_updated for x in updates)
TypeError: 'NoneType' object is not iterable
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


Discussion:
Seems like https://github.com/pymedusa/Medusa/blob/a70a6df42ec915a51409a059df3a58f56c1b2bd7/medusa/indexers/tvdbv2/tvdbv2_api.py#L564 can return None without raising an exception. A simple ```if updates is not None:``` right after it would do it. Or maybe we should raise an exception there.
yeah or:
`total_updates += [int(_.id) for _ in updates or []]`
@p0psicles 
The error happens a few lines before that:
```last_update_ts = max(x.last_updated for x in updates)```
We might also want to preserve the old ```from_time``` without overwriting it and still update the counter.
```
while updates and count < weeks:
    updates = self.updates_api.updated_query_get(from_time).data
    if updates is not None:
        last_update_ts = max(x.last_updated for x in updates)
        from_time = last_update_ts
        total_updates += [int(_.id) for _ in updates]
    count += 1
```

Resolving patch:
diff --git a/medusa/indexers/tvdbv2/tvdbv2_api.py b/medusa/indexers/tvdbv2/tvdbv2_api.py
--- a/medusa/indexers/tvdbv2/tvdbv2_api.py
+++ b/medusa/indexers/tvdbv2/tvdbv2_api.py
@@ -562,9 +562,10 @@ def get_last_updated_series(self, from_time, weeks=1, filter_show_list=None):
         try:
             while updates and count < weeks:
                 updates = self.updates_api.updated_query_get(from_time).data
-                last_update_ts = max(x.last_updated for x in updates)
-                from_time = last_update_ts
-                total_updates += [int(_.id) for _ in updates]
+                if updates is not None:
+                    last_update_ts = max(x.last_updated for x in updates)
+                    from_time = last_update_ts
+                    total_updates += [int(_.id) for _ in updates]
                 count += 1
         except (ApiException, MaxRetryError, RequestError) as e:
             raise IndexerUnavailable('Error connecting to Tvdb api. Caused by: {0!r}'.format(e))


Test patch: