Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trakt collection for TV shows got almost entirely cleared, not getting readded #622

Open
OttoWerse opened this issue Apr 4, 2022 · 23 comments

Comments

@OttoWerse
Copy link

Recently my library in Trakt got almost entirely cleared. I am using the clean collection setting, but nothing on my PMS was deleted so I have no idea why id did remove almost all my shows from Trakt now randomly. They are also not added back even after estarting everything, so now my Trakt library is just not syncing at all anymore. Movies seem unaffected.

@STJBaxter
Copy link

The same thing has happened to me. I've checked the plugin logs and it is full of the following message: "Invalid value provided for DateTimeField: 0123456789 (expected datetime instance)" - the number is a varaible, so it is different on each line.

I'm speculating, but maybe the new PMS version that I installed this week (1.26.0.5715 ) has changed the database slightly?

@kbgvirus
Copy link

The same thing has happened to me but for both movies and tv shows

@alexperrault
Copy link

Same issue here, just after upgrading to 1.26.0.5715.
Did some troubleshooting and came to the same conclusion.

Did anyone try to rollback to previous version (1.25.9.5721) ?

@jahmad
Copy link

jahmad commented Apr 23, 2022

Plex changed field type on metadata_items, from datetime to timestamp. the correct way to fix it would probably require update of pewee and some big changes. quick and dirty workaround, just convert it again..

on Trakttv.bundle/Contents/Libraries/Shared/plex_database/library.py (above the errored line).

--- library.py.orig     2022-04-23 15:14:49.784602915 +0700
+++ library.py  2022-04-23 15:10:09.340612008 +0700
@@ -183,6 +183,10 @@
             if not value:
                 return None

+            if isinstance(value, int):
+                value = datetime.fromtimestamp(value)
+
             if not isinstance(value, datetime):
                 log.debug('Invalid value provided for DateTimeField: %r (expected datetime instance)', value)
                 return None

@StroescuTheo
Copy link

Same issue here, just after upgrading to 1.26.0.5715. Did some troubleshooting and came to the same conclusion.

Did anyone try to rollback to previous version (1.25.9.5721) ?

Noticed the same issue. Both TvShows and Movies were missing from my trakt collection.
Just tried to rollback to tag 1.25.9.5721-965587f64 and ran a full sync on the trakt plugin and it worked. All my collected items synced to trakt

jahmad's workaround did not work for me.

@alexperrault
Copy link

I also rolled back to 1.25.9.5721 and everything went back to normal after a full sync.
I'll try @jahmad's workaround next week 👍

@the-jeffski
Copy link

The patch worked for me - all synced again.

@STJBaxter
Copy link

Patch worked for me too - thank you

@MarioMan632
Copy link

I think I did it the patch by @jahmad right but I'm still getting this error:
2022-04-25 19:29:08,980 - plex_database.library (14640be48b38) : DEBUG (plex_database.library:187) - Invalid value provided for DateTimeField: 1650456824 (expected datetime instance)

Here is the section of the library.py:

       if type(field) is DateTimeField:
           if not value:
               return None

           if isinstance(value, int):
               value = datetime.fromtimestamp(value)
               return value

           if not isinstance(value, datetime):
               log.debug('Invalid value provided for DateTimeField: %r (expected datetime instance)', value)
               return None

@STJBaxter
Copy link

STJBaxter commented Apr 25, 2022 via email

@the-jeffski
Copy link

Yes, just restarted the docker container so it all reloaded.

@MarioMan632
Copy link

I rebooted and it seems to be working, is this error going to be normal now?

TypeError: can't compare offset-naive and offset-aware datetimes
2022-04-25 20:12:54,820 - plugin.sync.modes.core.base.mode (14fce77eeb38) :  WARNING (plugin.sync.modes.core.base.mode:190) - Exception raised in handlers[1].run(8, ...): can't compare offset-naive and offset-aware datetimes
Traceback (most recent call last):
  File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/modes/core/base/mode.py", line 188, in execute_handlers
    self.handlers[d].run(m, mode, *args, **kwargs)
  File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/mode.py", line 42, in run
    module.run(media, mode, *args, **kwargs)
  File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/data.py", line 45, in run
    module.run(mode, *args, **kwargs)
  File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/media.py", line 95, in run
    return self.push(*args, **kwargs)
  File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/push.py", line 37, in push
    action = self.get_action(p_value, t_value)
  File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/push.py", line 23, in get_action
    if p_value != t_value:

@STJBaxter
Copy link

STJBaxter commented Apr 25, 2022 via email

@jahmad
Copy link

jahmad commented Apr 26, 2022

@MarioMan632 @STJBaxter an unfortunate useless line got pasted, sorry.. remove the "return value" line, so it could keep processed by the tz lines below.

@MarioMan632
Copy link

@jahmad I'll try it later to see if that helps but at the moment it works just with the errors stated before.

@Conundrum1911
Copy link

Plex changed field type on metadata_items, from datetime to timestamp. the correct way to fix it would probably require update of pewee and some big changes. quick and dirty workaround, just convert it again..

on Trakttv.bundle/Contents/Libraries/Shared/plex_database/library.py (above the errored line).

--- library.py.orig     2022-04-23 15:14:49.784602915 +0700
+++ library.py  2022-04-23 15:10:09.340612008 +0700
@@ -183,6 +183,10 @@
             if not value:
                 return None

+            if isinstance(value, int):
+                value = datetime.fromtimestamp(value)
+
             if not isinstance(value, datetime):
                 log.debug('Invalid value provided for DateTimeField: %r (expected datetime instance)', value)
                 return None

Forgive me, but where exactly do I put this in library.py? I just looked through that file and couldn't find any references.

Also in my case I don't see any errors jumping out at me, but it seems for the last month or so Plex has been syncing plays to Trakt, but not collections/items collected.

@StroescuTheo
Copy link

Plex changed field type on metadata_items, from datetime to timestamp. the correct way to fix it would probably require update of pewee and some big changes. quick and dirty workaround, just convert it again..
on Trakttv.bundle/Contents/Libraries/Shared/plex_database/library.py (above the errored line).

--- library.py.orig     2022-04-23 15:14:49.784602915 +0700
+++ library.py  2022-04-23 15:10:09.340612008 +0700
@@ -183,6 +183,10 @@
             if not value:
                 return None

+            if isinstance(value, int):
+                value = datetime.fromtimestamp(value)
+
             if not isinstance(value, datetime):
                 log.debug('Invalid value provided for DateTimeField: %r (expected datetime instance)', value)
                 return None

Forgive me, but where exactly do I put this in library.py? I just looked through that file and couldn't find any references.

Also in my case I don't see any errors jumping out at me, but it seems for the last month or so Plex has been syncing plays to Trakt, but not collections/items collected.

Hey! You can open a text editor and go at line 183. Around there you can identify the 2 "if" statements "if not value" and "if not isinstance" and add the extra if statement between them. Don't forget to restart the service/container for the change to take effect.

@Conundrum1911
Copy link

StroescuTheo -- Thanks, that was the bit I was missing in what to do. Lines added, and it appears to be syncing collections again. Strange though when I used Kitana to restart the plugin I got a bunch of errors/figured I had a syntax error but couldn't see anything. Restarted the entire plex process, used Kitana to do a full sync, and now all appears to be working.

@TobiasRuano
Copy link

I had the same issue and @jahmad solution worked!

@rg9400
Copy link
Contributor

rg9400 commented Aug 18, 2022

the patch by jahmad should be modified as below to allow timestamps to be compared. This is important for the differential push/pull (quick sync rather than scrobble) tasks, namely to pull stuff you watch on Trakt into Plex.

            if isinstance(value, int):
               value = datetime.fromtimestamp(value)
               return TZ_LOCAL.localize(value).astimezone(pytz.utc)

I am thinking to maybe figure out a way to host these patches in a separate fork so people can easily pull the latest code. But I haven't done some patches mentioned in various issues here because my current build works fine. I am worried those patches might break other things that are currently functional, so never added them.

EDIT: patched version here: https://github.com/rg9400/Plex-Trakt-Scrobbler
should have the patches to auto-grab Plex account from settings (since token is deprecated), as well as handle the new timestamp objects Plex is using (from this issue). Nothing else was included, but seems to be fully functional at my end

@Mushin
Copy link

Mushin commented Aug 18, 2022 via email

@carlosmg2
Copy link

the patch by jahmad should be modified as below to allow timestamps to be compared. This is important for the differential push/pull (quick sync rather than scrobble) tasks, namely to pull stuff you watch on Trakt into Plex.

            if isinstance(value, int):
               value = datetime.fromtimestamp(value)
               return TZ_LOCAL.localize(value).astimezone(pytz.utc)

I am thinking to maybe figure out a way to host these patches in a separate fork so people can easily pull the latest code. But I haven't done some patches mentioned in various issues here because my current build works fine. I am worried those patches might break other things that are currently functional, so never added them.

EDIT: patched version here: https://github.com/rg9400/Plex-Trakt-Scrobbler should have the patches to auto-grab Plex account from settings (since token is deprecated), as well as handle the new timestamp objects Plex is using (from this issue). Nothing else was included, but seems to be fully functional at my end

Thank you! Confirm this 3 edited files fix the Collection issue.

@karadoulis
Copy link

Hello, i have the same problem since the plex server update it doesn't sync anymore with trakt.tv at all. Tried the updated version but without success. Any help would be really appreciated it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests