Repository: pymedusa/Medusa

Issue:
Edit show is broken, at least for Anime
Version : 0.2.6 (through docker)
Basic stuff tried : Ive tried to reboot, rebuild the container from the last image, same result.

TL;DR : After adding a new anime show, if I edit the show, parameters are set to something else, and if corrected and saved, File location is lost.

Step 1 : I've added a new anime show, with "HD1080p" as quality and anime and scene numbering options, and unchecked folder for seasons  (like 20 sec before the screen shot) I didn't choose to whitelist a release group since it's currently bugged (in another issue) : 
<img width="587" alt="medusa 2018-07-08 00-35-28" src="https://user-images.githubusercontent.com/8405448/42415193-eaf2973c-8246-11e8-9c64-c02090e52e94.png">

 Step2 : I click on "Edit" on the show page : 
> On tab "MAIN" :  there "HD1080p" is replaced by "Custom" without any quality option checked, "default status episode" is empty. Also, the name of the Show is missing. 
> On tab "Format" : almost everything is wrong 
<img width="410" alt="edit show 2018-07-08 00-36-55" src="https://user-images.githubusercontent.com/8405448/42415202-127860de-8247-11e8-9d3a-10482a3524f9.png">

<img width="471" alt="edit show 2018-07-08 00-37-34" src="https://user-images.githubusercontent.com/8405448/42415205-2f18c1b6-8247-11e8-92a0-e975c08f3114.png">

Step3 : once I've corrected everything and click "Save", I go back to the show page and now Location is missing ...
<img width="389" alt="medusa - isekai maou to shoukan shoujo no dorei majutsu 2018-07-08 00-38-57" src="https://user-images.githubusercontent.com/8405448/42415208-57758068-8247-11e8-9570-a8ffd732c667.png">

I've tried it with 3 different anime, same result.

Bonus : if you can  whitelisted release group while adding the show (if you can because it's currently with the old UX which is bugged), for exemple "HorribleSubs" you could end up like me with "H","o","r","i","b","l","e","S","u","b","s" :)

Edit show is broken, at least for Anime
Version : 0.2.6 (through docker)
Basic stuff tried : Ive tried to reboot, rebuild the container from the last image, same result.

TL;DR : After adding a new anime show, if I edit the show, parameters are set to something else, and if corrected and saved, File location is lost.

Step 1 : I've added a new anime show, with "HD1080p" as quality and anime and scene numbering options, and unchecked folder for seasons  (like 20 sec before the screen shot) I didn't choose to whitelist a release group since it's currently bugged (in another issue) : 
<img width="587" alt="medusa 2018-07-08 00-35-28" src="https://user-images.githubusercontent.com/8405448/42415193-eaf2973c-8246-11e8-9c64-c02090e52e94.png">

 Step2 : I click on "Edit" on the show page : 
> On tab "MAIN" :  there "HD1080p" is replaced by "Custom" without any quality option checked, "default status episode" is empty. Also, the name of the Show is missing. 
> On tab "Format" : almost everything is wrong 
<img width="410" alt="edit show 2018-07-08 00-36-55" src="https://user-images.githubusercontent.com/8405448/42415202-127860de-8247-11e8-9d3a-10482a3524f9.png">

<img width="471" alt="edit show 2018-07-08 00-37-34" src="https://user-images.githubusercontent.com/8405448/42415205-2f18c1b6-8247-11e8-92a0-e975c08f3114.png">

Step3 : once I've corrected everything and click "Save", I go back to the show page and now Location is missing ...
<img width="389" alt="medusa - isekai maou to shoukan shoujo no dorei majutsu 2018-07-08 00-38-57" src="https://user-images.githubusercontent.com/8405448/42415208-57758068-8247-11e8-9570-a8ffd732c667.png">

I've tried it with 3 different anime, same result.

Bonus : if you can  whitelisted release group while adding the show (if you can because it's currently with the old UX which is bugged), for exemple "HorribleSubs" you could end up like me with "H","o","r","i","b","l","e","S","u","b","s" :)



Discussion:
Any errors in browsers console?
Also maybe a slow connection? Like you sure you gave it the time to load? 
Hello, thanks for your quick answer. I've tried to reproduced the problem, but something changed from yesterday. 

Yesterday I tried to add the following show : 
- Shichisei no Subaru (Main title) ; Seven Senses of the Re`Union (Official Title)
- Isekai Maou to Shoukan Shoujo no Dorei Majutsu (Maint title) ; How Not to Summon a Demon Lord (official title)

At the time, only TMDB indexer returned something for both shows and only while using the Main Title, Official title didn't returned anything on all indexer. And problems where encountered from there on these added shows with TMDB.

Today these 2 shows doesn't give result while searching with Maint title anymore, but TMDB return something on the Official title, and now TVDB and TVMaze return something also. Also XEM show up on the Show page, which wasn't the case yesterday.

From now the problem doesn't show up anymore, in the meantime I did'nt restart the server or anything else, tested and retested the issue on Safari, Firefox and Chrome like yesterday. Cache on webbrowser were's touched or cleared. And client (me) and server discussing over Lan, through direct local IP.

It a very strange behavior, do you think that maybe these show where too fresh (in indexer repository) and since there's obvious change made on TMDB between yesterday and today (It doesnt respond to the same title) it could had an impact on Medusa while it tries to build up the show from TMDB infos ? 
I really dont know. Hard to say if we cant reproduce it.

On a sidenote i would only use tvdb. The searching makes heavy use of xem. And that only works with tvdb.
Last time we had an issue like this it was a bad character encoding on our end (#4248, #4260).
@hergonoway 
You didn't get any errors in the logs?
I have the same version and this is also happening to me.

1º Added New Show without setting "Anime"  
2º Edit works!  
3º Edited Show to "Anime" and Saved  
4º Edit does not works  

editShow endpoint is pending without response.
No errors in Logs with debug active.
@sharkykh Unfortunatly logs don't come back this far, already generated 5 files of 10mb of logs till this morning .... I've changed that to 10 files of 50mb for the next time, sorry.
@gilfrade 
Which show is that?
I just tried `Seven Senses of the Re'Union` from TMDB with your steps and it works for me?
Also please check the browser's developer console (<kbd>F12</kbd> key or <kbd>CTRL+SHIFT+I</kbd>) for errors.
Seeing the exact same problem with 'Yume Oukoku to Nemureru 100-nin no Ouji-sama' (100 Sleeping Princes & The Kingdom of Dreams). Added as anime, the edit button doesn't present a usable page.

Have deleted and added multiple times. Full updated multiple times as well. Used Safari, Chrome, Oprea, Firefox with cleared caches.

![screenshot 2018-07-24 11 56 57](https://user-images.githubusercontent.com/566136/43160012-d2d90722-8f38-11e8-880d-c61afc33e136.png)

I'm still unable to reproduce this.
@alron 
Please check the browser's developer console (F12 key or CTRL+SHIFT+I) for errors.
If there aren't any, check the Network tab, refresh the page and then search for `/api/v2/series` (on the Network tab), and post the response it got here.
@sharkykh 
The only error showing on edit page is a 500 series error. Same error on network console (of course).
![100 sleeping princes - edit show console error](https://user-images.githubusercontent.com/566136/43215908-48d3df60-8ff2-11e8-9dfe-fd6f1a0c4252.png)

Seeing a 404 error on the show page itself. But this appears to be for the banner.
![100 sleeping princes - display show console error](https://user-images.githubusercontent.com/566136/43215805-069f68b2-8ff2-11e8-81fb-18cf090574c2.png)


Ok then we really need some debug logs at time of the 500 error
@p0psicles @sharkykh 
Looks like an exception in the tornado side of things.

Errors didn't start showing up in debug log until I enabled logging for tornado.

Let me know if there is anything else I can provide.

[error.txt](https://github.com/pymedusa/Medusa/files/2229255/error.txt)

That's good to know.

I have a workaround for it, but it won't fix the underlying issue.
@alron If you don't mind, I'd like your help in finding the issue. It requires some code editing.

Open this file:
https://github.com/pymedusa/Medusa/blob/e7c4ff3bc9a48b47c932b0e40a539d62e3a62f64/medusa/tv/episode.py#L1056

And replace that line with (note that the indentation is important):
```py
        try:
            data['airDate'] = self.air_date
        except Exception:
            ep_data = [
                'season: ' + repr(data['season']),
                'episode: ' + repr(data['episode']),
                'id: ' + repr(data['id']),
                'airdate: ' + repr(self.airdate),
                'airs: ' + repr(self.series.airs),
                'network: ' + repr(self.series.network)
            ]
            log.exception('Failed to convert air date for:\n{0}', '\n'.join(ep_data))
```

Save the file, restart Medusa, and navigate to the edit show page again.
The page will now load correctly, and you should get errors in the server logs.
Please post them here.

If you can do this, it will help a lot in figuring out the issue.

@hergonoway 
@gilfrade
You are welcome to try this too, just in case the errors you're getting are different.
@sharkykh Roger that. I'll give it a whirl. Will post results shortly.
@sharkykh Looks like that handled the exception a bit better and made the edit show page work. 
![screenshot 2018-07-25 20 29 13](https://user-images.githubusercontent.com/566136/43240034-8692a9b0-9049-11e8-929f-50096e5ab402.png)

Log:
[error.txt](https://github.com/pymedusa/Medusa/files/2230351/error.txt)

edit: 
also verified that saving edits work. was able to successfully set the wanted group. 
@alron 
Thank you.
I'm still unable to reproduce this error, which makes it very hard for me to find the actual issue.
Maybe this is related - I'm running Medusa on Windows 7, what OS are you running?
@sharkykh 
Docker 18.06.0~ce~3-0~ubuntu using the pymedusa/medusa image.
Base system docker lives on is Ubuntu Linux 18.04, kernel 4.15.0-24-generic. 
Using nginx as HTTPS proxy for the UI. 
Huh, Docker too. Just like OP. Interesting.

I'll set up a Docker environment to test this.

In the meantime, if could you do one more code change please...
https://github.com/pymedusa/Medusa/blob/e7c4ff3bc9a48b47c932b0e40a539d62e3a62f64/medusa/tv/episode.py#L404-L410

Change these lines to:
```py
        airdate = date.toordinal(self.airdate)
        airtime = network_timezones.parse_date_time(airdate, self.series.airs, self.series.network)
        apptime = sbdatetime.convert_to_setting(airtime)
        return apptime.isoformat(b'T')
```

Same deal, save file, restart Medusa, go to edit show page and check the error logs.
Modified, restarted, triggered.

[error.txt](https://github.com/pymedusa/Medusa/files/2230447/error.txt)

I still can't reproduce it, even inside a Docker container.

Could you change
```py
        apptime = sbdatetime.convert_to_setting(airtime)
        return apptime.isoformat(b'T')
```
to:
```py
        apptime = sbdatetime.convert_to_setting(airtime)
        log.warning('Airtime is: {0!r}', apptime)
        return apptime.isoformat(b'T')
```

Could you also check your timezone inside the container?
Maybe it's related...
Timezone is set and reporting properly via cli utilities. 

Modified, restarted, triggered.

[error.txt](https://github.com/pymedusa/Medusa/files/2230592/error.txt)

I still think it's somehow related to timezone setting, because I don't get the error.
Can you please run the following command inside the container?
```
python -c "import time; print time.timezone, time.altzone, time.tzname"
```

```
root@a8874e476ce7:/$ python --version
Python 2.7.14
root@a8874e476ce7:/$ python -c "import time; print time.timezone, time.altzone, time.tzname"
28800 25200 ('PST', 'PDT')
```
Alright, now I'm getting somewhere:
I assume you set the timezone using (for example):
```shell
export TZ=America/Los_Angeles
```

I did that too. Then I did the following:
```
cd /app/medusa/ext
python -c "import datetime; from dateutil.tz import tzlocal; print datetime.datetime(1, 1, 1, 0, 0, tzinfo=tzlocal()).isoformat(b'T')"
```
Then I got the same error. Please try that on your container to make sure.

Yep. That'd be the timezone. 
I also have /usr/share/zoneinfo/US/Pacific:/etc/localtime:ro as a mount, so the zoneinfo is correct.
```
root@a8874e476ce7:/$ cd /app/medusa/ext
root@a8874e476ce7:/app/medusa/ext$ python -c "import datetime; from dateutil.tz import tzlocal; print datetime.datetime(1, 1, 1, 0, 0, tzinfo=tzlocal()).isoformat(b'T')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "dateutil/tz/tz.py", line 210, in utcoffset
    if self._isdst(dt):
  File "dateutil/tz/tz.py", line 282, in _isdst
    if self.is_ambiguous(dt):
  File "dateutil/tz/tz.py", line 244, in is_ambiguous
    (naive_dst != self._naive_is_dst(dt - self._dst_saved)))
OverflowError: date value out of range
```
Also if you look on the footer of each page on Medusa, is the "Now" time correct for you?
![screenshot 2018-07-25 23 58 19](https://user-images.githubusercontent.com/566136/43246486-a399aff0-9066-11e8-9d5d-8457e8bf96c8.png)

Looks correct.
Try on the container:
```
cat /etc/localtime
```
You very much so don't want me to cat /etc/localtime. It is binary TZ data. 

Then `less`. I just want to make sure everything is set correctly.
What I'm trying to figure out is where a timezone setting is missing.

By the way for me, on the newly created container `/etc/localtime` is UTC, so it's small.
```
root@328005d0485e:/$ cat /etc/localtime
TZif2UTCTZif2UTC
UTC0
```

I don't use Linux regularly so sorry if I'm being meticulous with my checks.
Ok, nevermind. I think I know why it doesn't work.
I'm pretty positive I have my dockers all set up properly. :)

My localtime is a docker filesystem mount of my host system /usr/share/zoneinfo/America/Los_Angeles (via the /usr/share/zoneinfo/US/Pacific symlink).

Have the first and last lines of the file. Pretty sure the last line is what you care about anyways.
```
root@a8874e476ce7:/$ strings /etc/localtime
TZif2
...
PST8PDT,M3.2.0,M11.1.0
```
Any errors in browsers console?
Also maybe a slow connection? Like you sure you gave it the time to load? 
Hello, thanks for your quick answer. I've tried to reproduced the problem, but something changed from yesterday. 

Yesterday I tried to add the following show : 
- Shichisei no Subaru (Main title) ; Seven Senses of the Re`Union (Official Title)
- Isekai Maou to Shoukan Shoujo no Dorei Majutsu (Maint title) ; How Not to Summon a Demon Lord (official title)

At the time, only TMDB indexer returned something for both shows and only while using the Main Title, Official title didn't returned anything on all indexer. And problems where encountered from there on these added shows with TMDB.

Today these 2 shows doesn't give result while searching with Maint title anymore, but TMDB return something on the Official title, and now TVDB and TVMaze return something also. Also XEM show up on the Show page, which wasn't the case yesterday.

From now the problem doesn't show up anymore, in the meantime I did'nt restart the server or anything else, tested and retested the issue on Safari, Firefox and Chrome like yesterday. Cache on webbrowser were's touched or cleared. And client (me) and server discussing over Lan, through direct local IP.

It a very strange behavior, do you think that maybe these show where too fresh (in indexer repository) and since there's obvious change made on TMDB between yesterday and today (It doesnt respond to the same title) it could had an impact on Medusa while it tries to build up the show from TMDB infos ? 
I really dont know. Hard to say if we cant reproduce it.

On a sidenote i would only use tvdb. The searching makes heavy use of xem. And that only works with tvdb.
Last time we had an issue like this it was a bad character encoding on our end (#4248, #4260).
@hergonoway 
You didn't get any errors in the logs?
I have the same version and this is also happening to me.

1º Added New Show without setting "Anime"  
2º Edit works!  
3º Edited Show to "Anime" and Saved  
4º Edit does not works  

editShow endpoint is pending without response.
No errors in Logs with debug active.
@sharkykh Unfortunatly logs don't come back this far, already generated 5 files of 10mb of logs till this morning .... I've changed that to 10 files of 50mb for the next time, sorry.
@gilfrade 
Which show is that?
I just tried `Seven Senses of the Re'Union` from TMDB with your steps and it works for me?
Also please check the browser's developer console (<kbd>F12</kbd> key or <kbd>CTRL+SHIFT+I</kbd>) for errors.
Seeing the exact same problem with 'Yume Oukoku to Nemureru 100-nin no Ouji-sama' (100 Sleeping Princes & The Kingdom of Dreams). Added as anime, the edit button doesn't present a usable page.

Have deleted and added multiple times. Full updated multiple times as well. Used Safari, Chrome, Oprea, Firefox with cleared caches.

![screenshot 2018-07-24 11 56 57](https://user-images.githubusercontent.com/566136/43160012-d2d90722-8f38-11e8-880d-c61afc33e136.png)

I'm still unable to reproduce this.
@alron 
Please check the browser's developer console (F12 key or CTRL+SHIFT+I) for errors.
If there aren't any, check the Network tab, refresh the page and then search for `/api/v2/series` (on the Network tab), and post the response it got here.
@sharkykh 
The only error showing on edit page is a 500 series error. Same error on network console (of course).
![100 sleeping princes - edit show console error](https://user-images.githubusercontent.com/566136/43215908-48d3df60-8ff2-11e8-9dfe-fd6f1a0c4252.png)

Seeing a 404 error on the show page itself. But this appears to be for the banner.
![100 sleeping princes - display show console error](https://user-images.githubusercontent.com/566136/43215805-069f68b2-8ff2-11e8-81fb-18cf090574c2.png)


Ok then we really need some debug logs at time of the 500 error
@p0psicles @sharkykh 
Looks like an exception in the tornado side of things.

Errors didn't start showing up in debug log until I enabled logging for tornado.

Let me know if there is anything else I can provide.

[error.txt](https://github.com/pymedusa/Medusa/files/2229255/error.txt)

That's good to know.

I have a workaround for it, but it won't fix the underlying issue.
@alron If you don't mind, I'd like your help in finding the issue. It requires some code editing.

Open this file:
https://github.com/pymedusa/Medusa/blob/e7c4ff3bc9a48b47c932b0e40a539d62e3a62f64/medusa/tv/episode.py#L1056

And replace that line with (note that the indentation is important):
```py
        try:
            data['airDate'] = self.air_date
        except Exception:
            ep_data = [
                'season: ' + repr(data['season']),
                'episode: ' + repr(data['episode']),
                'id: ' + repr(data['id']),
                'airdate: ' + repr(self.airdate),
                'airs: ' + repr(self.series.airs),
                'network: ' + repr(self.series.network)
            ]
            log.exception('Failed to convert air date for:\n{0}', '\n'.join(ep_data))
```

Save the file, restart Medusa, and navigate to the edit show page again.
The page will now load correctly, and you should get errors in the server logs.
Please post them here.

If you can do this, it will help a lot in figuring out the issue.

@hergonoway 
@gilfrade
You are welcome to try this too, just in case the errors you're getting are different.
@sharkykh Roger that. I'll give it a whirl. Will post results shortly.
@sharkykh Looks like that handled the exception a bit better and made the edit show page work. 
![screenshot 2018-07-25 20 29 13](https://user-images.githubusercontent.com/566136/43240034-8692a9b0-9049-11e8-929f-50096e5ab402.png)

Log:
[error.txt](https://github.com/pymedusa/Medusa/files/2230351/error.txt)

edit: 
also verified that saving edits work. was able to successfully set the wanted group. 
@alron 
Thank you.
I'm still unable to reproduce this error, which makes it very hard for me to find the actual issue.
Maybe this is related - I'm running Medusa on Windows 7, what OS are you running?
@sharkykh 
Docker 18.06.0~ce~3-0~ubuntu using the pymedusa/medusa image.
Base system docker lives on is Ubuntu Linux 18.04, kernel 4.15.0-24-generic. 
Using nginx as HTTPS proxy for the UI. 
Huh, Docker too. Just like OP. Interesting.

I'll set up a Docker environment to test this.

In the meantime, if could you do one more code change please...
https://github.com/pymedusa/Medusa/blob/e7c4ff3bc9a48b47c932b0e40a539d62e3a62f64/medusa/tv/episode.py#L404-L410

Change these lines to:
```py
        airdate = date.toordinal(self.airdate)
        airtime = network_timezones.parse_date_time(airdate, self.series.airs, self.series.network)
        apptime = sbdatetime.convert_to_setting(airtime)
        return apptime.isoformat(b'T')
```

Same deal, save file, restart Medusa, go to edit show page and check the error logs.
Modified, restarted, triggered.

[error.txt](https://github.com/pymedusa/Medusa/files/2230447/error.txt)

I still can't reproduce it, even inside a Docker container.

Could you change
```py
        apptime = sbdatetime.convert_to_setting(airtime)
        return apptime.isoformat(b'T')
```
to:
```py
        apptime = sbdatetime.convert_to_setting(airtime)
        log.warning('Airtime is: {0!r}', apptime)
        return apptime.isoformat(b'T')
```

Could you also check your timezone inside the container?
Maybe it's related...
Timezone is set and reporting properly via cli utilities. 

Modified, restarted, triggered.

[error.txt](https://github.com/pymedusa/Medusa/files/2230592/error.txt)

I still think it's somehow related to timezone setting, because I don't get the error.
Can you please run the following command inside the container?
```
python -c "import time; print time.timezone, time.altzone, time.tzname"
```

```
root@a8874e476ce7:/$ python --version
Python 2.7.14
root@a8874e476ce7:/$ python -c "import time; print time.timezone, time.altzone, time.tzname"
28800 25200 ('PST', 'PDT')
```
Alright, now I'm getting somewhere:
I assume you set the timezone using (for example):
```shell
export TZ=America/Los_Angeles
```

I did that too. Then I did the following:
```
cd /app/medusa/ext
python -c "import datetime; from dateutil.tz import tzlocal; print datetime.datetime(1, 1, 1, 0, 0, tzinfo=tzlocal()).isoformat(b'T')"
```
Then I got the same error. Please try that on your container to make sure.

Yep. That'd be the timezone. 
I also have /usr/share/zoneinfo/US/Pacific:/etc/localtime:ro as a mount, so the zoneinfo is correct.
```
root@a8874e476ce7:/$ cd /app/medusa/ext
root@a8874e476ce7:/app/medusa/ext$ python -c "import datetime; from dateutil.tz import tzlocal; print datetime.datetime(1, 1, 1, 0, 0, tzinfo=tzlocal()).isoformat(b'T')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "dateutil/tz/tz.py", line 210, in utcoffset
    if self._isdst(dt):
  File "dateutil/tz/tz.py", line 282, in _isdst
    if self.is_ambiguous(dt):
  File "dateutil/tz/tz.py", line 244, in is_ambiguous
    (naive_dst != self._naive_is_dst(dt - self._dst_saved)))
OverflowError: date value out of range
```
Also if you look on the footer of each page on Medusa, is the "Now" time correct for you?
![screenshot 2018-07-25 23 58 19](https://user-images.githubusercontent.com/566136/43246486-a399aff0-9066-11e8-9d5d-8457e8bf96c8.png)

Looks correct.
Try on the container:
```
cat /etc/localtime
```
You very much so don't want me to cat /etc/localtime. It is binary TZ data. 

Then `less`. I just want to make sure everything is set correctly.
What I'm trying to figure out is where a timezone setting is missing.

By the way for me, on the newly created container `/etc/localtime` is UTC, so it's small.
```
root@328005d0485e:/$ cat /etc/localtime
TZif2UTCTZif2UTC
UTC0
```

I don't use Linux regularly so sorry if I'm being meticulous with my checks.
Ok, nevermind. I think I know why it doesn't work.
I'm pretty positive I have my dockers all set up properly. :)

My localtime is a docker filesystem mount of my host system /usr/share/zoneinfo/America/Los_Angeles (via the /usr/share/zoneinfo/US/Pacific symlink).

Have the first and last lines of the file. Pretty sure the last line is what you care about anyways.
```
root@a8874e476ce7:/$ strings /etc/localtime
TZif2
...
PST8PDT,M3.2.0,M11.1.0
```

Resolving patch:
diff --git a/medusa/server/api/v2/alias.py b/medusa/server/api/v2/alias.py
--- a/medusa/server/api/v2/alias.py
+++ b/medusa/server/api/v2/alias.py
@@ -3,7 +3,6 @@
 from __future__ import unicode_literals
 
 from medusa import db
-from medusa.helper.mappings import NonEmptyDict
 from medusa.server.api.v2.base import BaseRequestHandler
 from medusa.tv.series import SeriesIdentifier
 
@@ -71,7 +70,7 @@ def get(self, identifier, path_param):
 
         data = []
         for item in sql_results:
-            d = NonEmptyDict()
+            d = {}
             d['id'] = item[0]
             d['series'] = SeriesIdentifier.from_id(item[1], item[2]).slug
             d['name'] = item[3]
diff --git a/medusa/tv/episode.py b/medusa/tv/episode.py
--- a/medusa/tv/episode.py
+++ b/medusa/tv/episode.py
@@ -58,7 +58,6 @@
     NoNFOException,
     ex,
 )
-from medusa.helper.mappings import NonEmptyDict
 from medusa.indexers.indexer_api import indexerApi
 from medusa.indexers.indexer_config import indexerConfig
 from medusa.indexers.indexer_exceptions import (
@@ -401,6 +400,9 @@ def indexer_name(self):
     @property
     def air_date(self):
         """Return air date from the episode."""
+        if self.airdate == date.min:
+            return None
+
         return sbdatetime.convert_to_setting(
             network_timezones.parse_date_time(
                 date.toordinal(self.airdate),
@@ -1044,7 +1046,7 @@ def __str__(self):
 
     def to_json(self, detailed=True):
         """Return the json representation."""
-        data = NonEmptyDict()
+        data = {}
         data['identifier'] = self.identifier
         data['id'] = {self.indexer_name: self.indexerid}
         data['season'] = self.season
@@ -1061,19 +1063,19 @@ def to_json(self, detailed=True):
         data['subtitles'] = self.subtitles
         data['status'] = self.status_name
         data['quality'] = self.quality
-        data['release'] = NonEmptyDict()
+        data['release'] = {}
         data['release']['name'] = self.release_name
         data['release']['group'] = self.release_group
         data['release']['proper'] = self.is_proper
         data['release']['version'] = self.version
-        data['scene'] = NonEmptyDict()
+        data['scene'] = {}
         data['scene']['season'] = self.scene_season
         data['scene']['episode'] = self.scene_episode
 
         if self.scene_absolute_number:
             data['scene']['absoluteNumber'] = self.scene_absolute_number
 
-        data['file'] = NonEmptyDict()
+        data['file'] = {}
         data['file']['location'] = self.location
         if self.file_size:
             data['file']['size'] = self.file_size
@@ -1084,8 +1086,8 @@ def to_json(self, detailed=True):
             data['content'].append('thumbnail')
 
         if detailed:
-            data['statistics'] = NonEmptyDict()
-            data['statistics']['subtitleSearch'] = NonEmptyDict()
+            data['statistics'] = {}
+            data['statistics']['subtitleSearch'] = {}
             data['statistics']['subtitleSearch']['last'] = self.subtitles_lastsearch
             data['statistics']['subtitleSearch']['count'] = self.subtitles_searchcount
             data['wantedQualities'] = self.wanted_quality
diff --git a/medusa/tv/series.py b/medusa/tv/series.py
--- a/medusa/tv/series.py
+++ b/medusa/tv/series.py
@@ -61,7 +61,6 @@
     ShowNotFoundException,
     ex,
 )
-from medusa.helper.mappings import NonEmptyDict
 from medusa.helpers.anidb import get_release_groups_for_anime, short_group_names
 from medusa.helpers.externals import get_externals, load_externals_from_db
 from medusa.helpers.utils import safe_get
@@ -1958,8 +1957,8 @@ def to_json(self, detailed=True):
         """Return JSON representation."""
         bw_list = self.release_groups or BlackAndWhiteList(self)
 
-        data = NonEmptyDict()
-        data['id'] = NonEmptyDict()
+        data = {}
+        data['id'] = {}
         data['id'][self.indexer_name] = self.series_id
         data['id']['imdb'] = text_type(self.imdb_id)
         data['id']['slug'] = self.identifier.slug
@@ -1972,27 +1971,27 @@ def to_json(self, detailed=True):
         data['language'] = self.lang
         data['showType'] = self.show_type  # e.g. anime, sport, series
         data['akas'] = self.imdb_akas
-        data['year'] = NonEmptyDict()
+        data['year'] = {}
         data['year']['start'] = self.imdb_year or self.start_year
         data['nextAirDate'] = self.next_airdate.isoformat() if self.next_airdate else None
         data['runtime'] = self.imdb_runtime or self.runtime
         data['genres'] = self.genres
-        data['rating'] = NonEmptyDict()
+        data['rating'] = {}
         if self.imdb_rating and self.imdb_votes:
-            data['rating']['imdb'] = NonEmptyDict()
+            data['rating']['imdb'] = {}
             data['rating']['imdb']['rating'] = self.imdb_rating
             data['rating']['imdb']['votes'] = self.imdb_votes
 
         data['classification'] = self.imdb_certificates
-        data['cache'] = NonEmptyDict()
+        data['cache'] = {}
         data['cache']['poster'] = self.poster
         data['cache']['banner'] = self.banner
         data['countries'] = self.countries  # e.g. ['ITALY', 'FRANCE']
         data['country_codes'] = self.imdb_countries  # e.g. ['it', 'fr']
         data['plot'] = self.plot or self.imdb_plot
-        data['config'] = NonEmptyDict()
+        data['config'] = {}
         data['config']['location'] = self.raw_location
-        data['config']['qualities'] = NonEmptyDict()
+        data['config']['qualities'] = {}
         data['config']['qualities']['allowed'] = self.qualities_allowed
         data['config']['qualities']['preferred'] = self.qualities_preferred
         data['config']['paused'] = bool(self.paused)
@@ -2006,7 +2005,7 @@ def to_json(self, detailed=True):
         data['config']['paused'] = bool(self.paused)
         data['config']['defaultEpisodeStatus'] = self.default_ep_status_name
         data['config']['aliases'] = list(self.aliases)
-        data['config']['release'] = NonEmptyDict()
+        data['config']['release'] = {}
         # These are for now considered anime-only options, as they query anidb for available release groups.
         if self.is_anime:
             data['config']['release']['blacklist'] = bw_list.blacklist


Test patch: