Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: AttributeError: 'NoneType' object has no attribute 'isoformat'

### INFO
**Python Version**: `3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]`
**Operating System**: `Windows-7-6.1.7601-SP1`
**Locale**: `cp1252`
**Branch**: [master](../tree/master)
**Database**: `44.19`
**Commit**: pymedusa/Medusa@dd0b95038397b50db5d404a972f6202ddb932556
**Link to Log**: **No Log available**
### ERROR
<pre>
2022-02-13 08:15:12 ERROR    TORNADO :: [dd0b950] Uncaught exception in APIv2: AttributeError("'NoneType' object has no attribute 'isoformat'")
Request: GET /api/v2/internal/getEpisodeBacklog?period=all&status=all (192.168.10.75)
Traceback (most recent call last):
  File "C:\Medusa\Medusa\<a href="../blob/dd0b95038397b50db5d404a972f6202ddb932556/ext/tornado/web.py#L1704">ext\tornado\web.py</a>", line 1704, in _execute
    result = await result
  File "C:\Medusa\Medusa\<a href="../blob/dd0b95038397b50db5d404a972f6202ddb932556/ext/tornado/gen.py#L769">ext\tornado\gen.py</a>", line 769, in run
    yielded = self.gen.throw(*exc_info)  # type: ignore
  File "C:\Medusa\Medusa\<a href="../blob/dd0b95038397b50db5d404a972f6202ddb932556/medusa/server/api/v2/base.py#L64">medusa\server\api\v2\base.py</a>", line 64, in async_call
    content = yield IOLoop.current().run_in_executor(executor, prepared)
  File "C:\Medusa\Medusa\<a href="../blob/dd0b95038397b50db5d404a972f6202ddb932556/ext/tornado/gen.py#L762">ext\tornado\gen.py</a>", line 762, in run
    value = future.result()
  File "C:\Medusa\Python\lib\concurrent\futures\thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Medusa\Medusa\<a href="../blob/dd0b95038397b50db5d404a972f6202ddb932556/medusa/server/api/v2/internal.py#L68">medusa\server\api\v2\internal.py</a>", line 68, in get
    return resource_function()
  File "C:\Medusa\Medusa\<a href="../blob/dd0b95038397b50db5d404a972f6202ddb932556/medusa/server/api/v2/internal.py#L407">medusa\server\api\v2\internal.py</a>", line 407, in resource_get_episode_backlog
    cur_result['airdate'] = air_date.isoformat('T')
AttributeError: 'NoneType' object has no attribute 'isoformat'
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:

### INFO
**Python Version**: `3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]`
**Operating System**: `Windows-7-6.1.7601-SP1`
**Locale**: `cp1252`
**Branch**: [master](../tree/master)
**Database**: `44.19`
**Commit**: pymedusa/Medusa@e4870f8f4a322e67c77434597ccc09aa6524aa05
**Link to Log**: **No Log available**
### ERROR
<pre>
2022-04-21 11:54:25 ERROR    TORNADO :: [e4870f8] Uncaught exception in APIv2: AttributeError("'NoneType' object has no attribute 'isoformat'")
Request: GET /api/v2/internal/getEpisodeBacklog?period=all&status=all (192.168.10.76)
Traceback (most recent call last):
  File "C:\Medusa\Medusa\<a href="../blob/e4870f8f4a322e67c77434597ccc09aa6524aa05/ext/tornado/web.py#L1704">ext\tornado\web.py</a>", line 1704, in _execute
    result = await result
  File "C:\Medusa\Medusa\<a href="../blob/e4870f8f4a322e67c77434597ccc09aa6524aa05/ext/tornado/gen.py#L769">ext\tornado\gen.py</a>", line 769, in run
    yielded = self.gen.throw(*exc_info)  # type: ignore
  File "C:\Medusa\Medusa\<a href="../blob/e4870f8f4a322e67c77434597ccc09aa6524aa05/medusa/server/api/v2/base.py#L64">medusa\server\api\v2\base.py</a>", line 64, in async_call
    content = yield IOLoop.current().run_in_executor(executor, prepared)
  File "C:\Medusa\Medusa\<a href="../blob/e4870f8f4a322e67c77434597ccc09aa6524aa05/ext/tornado/gen.py#L762">ext\tornado\gen.py</a>", line 762, in run
    value = future.result()
  File "C:\Medusa\Python\lib\concurrent\futures\thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Medusa\Medusa\<a href="../blob/e4870f8f4a322e67c77434597ccc09aa6524aa05/medusa/server/api/v2/internal.py#L70">medusa\server\api\v2\internal.py</a>", line 70, in get
    return resource_function()
  File "C:\Medusa\Medusa\<a href="../blob/e4870f8f4a322e67c77434597ccc09aa6524aa05/medusa/server/api/v2/internal.py#L409">medusa\server\api\v2\internal.py</a>", line 409, in resource_get_episode_backlog
    cur_result['airdate'] = air_date.isoformat('T')
AttributeError: 'NoneType' object has no attribute 'isoformat'
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


Resolving patch:
diff --git a/medusa/server/api/v2/internal.py b/medusa/server/api/v2/internal.py
--- a/medusa/server/api/v2/internal.py
+++ b/medusa/server/api/v2/internal.py
@@ -406,7 +406,7 @@ def resource_get_episode_backlog(self):
                         cur_ep_cat_string = Overview.overviewStrings[cur_ep_cat]
                         ep_cats[episode_string] = cur_ep_cat_string
                         ep_counts[cur_ep_cat_string] += 1
-                        cur_result['airdate'] = air_date.isoformat('T')
+                        cur_result['airdate'] = air_date.isoformat('T') if air_date else ''
                         cur_result['manuallySearched'] = cur_result['manually_searched']
                         del cur_result['manually_searched']
                         cur_result['statusString'] = statusStrings[cur_result['status']]


Test patch: