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

Error running clear_collections command #2026

Open
3 tasks done
jrcorwin opened this issue Aug 19, 2024 · 3 comments
Open
3 tasks done

Error running clear_collections command #2026

jrcorwin opened this issue Aug 19, 2024 · 3 comments

Comments

@jrcorwin
Copy link

Confirmation

  • I have read the README.md on the project homepage
  • I have checked if identical issue already exists
  • I have tried downgrading to find version that can be used as a workaround

The problem

Running the clear collections command results in an error of generator raised StopIteration and appears to be hit once it transitions from clearing movies to TV shows.

Steps to reproduce the behavior

Issue plextraktsync clear-collections --confirm command

Error trace / logs

ERROR    generator raised StopIteration                                                                                                                                                                                                                                
         ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
         │ /home/elfie/.local/pipx/venvs/PlexTraktSync/lib/python3.8/site-packages/trakt/users.py:498 in show_collection                                                                                                                                              │
         │                                                                                                                                                                                                                                                            │
         │   495 │   │   │   │   for season in seasons:                                                                                                                                                                                                               │
         │   496 │   │   │   │   │   ts = next(s for s in full_show.seasons if s.season ==                                                                                                                                                                            │
         │       season.get('number'))                                                                                                                                                                                                                                │
         │   497 │   │   │   │   │   for ep in season.get('episodes'):                                                                                                                                                                                                │
         │ ❱ 498 │   │   │   │   │   │   te = next(e for e in ts.episodes if e.number ==                                                                                                                                                                              │
         │       ep.get('number'))                                                                                                                                                                                                                                    │
         │   499 │   │   │   │   │   │   ep['title'] = te.title                                                                                                                                                                                                       │
         │   500 │   │   │   │   │   │   ep.update(te.ids)                                                                                                                                                                                                            │
         │   501 │   │   │   │   del te, ts, full_show                                                                                                                                                                                                                │
         ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
         StopIteration                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                       
         The above exception was the direct cause of the following exception:                                                                                                                                                                                          
                                                                                                                                                                                                                                                                       
         ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
         │ /home/elfie/.local/pipx/venvs/PlexTraktSync/lib/python3.8/site-packages/plextraktsync/cli.py:28 in wrap                                                                                                                                                    │
         │                                                                                                                                                                                                                                                            │
         │    25 │   │   │   cmd = getattr(module, name)                                                                                                                                                                                                              │
         │    26 │   │   │                                                                                                                                                                                                                                            │
         │    27 │   │   │   try:                                                                                                                                                                                                                                     │
         │ ❱  28 │   │   │   │   cmd(*args, **kwargs)                                                                                                                                                                                                                 │
         │    29 │   │   │   except EOFError as e:                                                                                                                                                                                                                    │
         │    30 │   │   │   │   raise ClickException(f"Program requested terminal, No terminal is                                                                                                                                                                    │
         │       connected: {e}")                                                                                                                                                                                                                                     │
         │    31 │   │   │   except ClickException as e:                                                                                                                                                                                                              │
         │                                                                                                                                                                                                                                                            │
         │ /home/elfie/.local/pipx/venvs/PlexTraktSync/lib/python3.8/site-packages/plextraktsync/commands/clear_collections.py:22 in clear_collections                                                                                                                │
         │                                                                                                                                                                                                                                                            │
         │   19 │   │   if not dry_run:                                                                                                                                                                                                                               │
         │   20 │   │   │   trakt.remove_from_collection(movie)                                                                                                                                                                                                       │
         │   21 │                                                                                                                                                                                                                                                     │
         │ ❱ 22 │   for show in trakt.show_collection if shows else []:                                                                                                                                                                                               │
         │   23 │   │   logger.info(f"Deleting from Trakt: {show}")                                                                                                                                                                                                   │
         │   24 │   │   if not dry_run:                                                                                                                                                                                                                               │
         │   25 │   │   │   trakt.remove_from_collection(show)                                                                                                                                                                                                        │
         │   229 │   │   def fun(*args, **kw):                                                                                                                                                                                                                        │
         │   230 │   │   │   if not kwsyntax:                                                                                                                                                                                                                         │
         │   231 │   │   │   │   args, kw = fix(args, kw, sig)                                                                                                                                                                                                        │
         │ ❱ 232 │   │   │   return caller(func, *(extras + args), **kw)                                                                                                                                                                                              │
         │   233 │   fun.__name__ = func.__name__                                                                                                                                                                                                                     │
         │   234 │   fun.__doc__ = func.__doc__                                                                                                                                                                                                                       │
         │   235 │   fun.__wrapped__ = func                                                                                                                                                                                                                           │
         │                                                                                                                                                                                                                                                            │
         │ /home/elfie/.local/pipx/venvs/PlexTraktSync/lib/python3.8/site-packages/plextraktsync/decorators/rate_limit.py:20 in rate_limit                                                                                                                            │
         │                                                                                                                                                                                                                                                            │
         │   17 │   retry = 0                                                                                                                                                                                                                                         │
         │   18 │   while True:                                                                                                                                                                                                                                       │
         │   19 │   │   try:                                                                                                                                                                                                                                          │
         │ ❱ 20 │   │   │   return fn(*args, **kwargs)                                                                                                                                                                                                                │
         │   21 │   │   except RateLimitException as e:                                                                                                                                                                                                               │
         │   22 │   │   │   if retry == retries:                                                                                                                                                                                                                      │
         │   23 │   │   │   │   logger.error(f"Trakt Error: {e}")                                                                                                                                                                                                     │
         │                                                                                                                                                                                                                                                            │
         │ /home/elfie/.local/pipx/venvs/PlexTraktSync/lib/python3.8/site-packages/decorator.py:232 in fun                                                                                                                                                            │
         │                                                                                                                                                                                                                                                            │
         │   229 │   │   def fun(*args, **kw):                                                                                                                                                                                                                        │
         │   230 │   │   │   if not kwsyntax:                                                                                                                                                                                                                         │
         │   231 │   │   │   │   args, kw = fix(args, kw, sig)                                                                                                                                                                                                        │
         │ ❱ 232 │   │   │   return caller(func, *(extras + args), **kw)                                                                                                                                                                                              │
         │   233 │   fun.__name__ = func.__name__                                                                                                                                                                                                                     │
         │   234 │   fun.__doc__ = func.__doc__                                                                                                                                                                                                                       │
         │   235 │   fun.__wrapped__ = func                                                                                                                                                                                                                           │
         │                                                                                                                                                                                                                                                            │
         │ /home/elfie/.local/pipx/venvs/PlexTraktSync/lib/python3.8/site-packages/plextraktsync/decorators/retry.py:26 in retry                                                                                                                                      │
         │                                                                                                                                                                                                                                                            │
         │   23 │   count = 0                                                                                                                                                                                                                                         │
         │   24 │   while True:                                                                                                                                                                                                                                       │
         │   25 │   │   try:                                                                                                                                                                                                                                          │
         │ ❱ 26 │   │   │   return fn(*args, **kwargs)                                                                                                                                                                                                                │
         │   27 │   │   except (                                                                                                                                                                                                                                      │
         │   28 │   │   │   BadRequest,                                                                                                                                                                                                                               │
         │   29 │   │   │   BadResponseException,                                                                                                                                                                                                                     │
         │                                                                                                                                                                                                                                                            │
         │ /home/elfie/.local/pipx/venvs/PlexTraktSync/lib/python3.8/site-packages/plextraktsync/trakt/TraktApi.py:109 in show_collection                                                                                                                             │
         │                                                                                                                                                                                                                                                            │
         │   106 │   @rate_limit()                                                                                                                                                                                                                                    │
         │   107 │   @retry()                                                                                                                                                                                                                                         │
         │   108 │   def show_collection(self):                                                                                                                                                                                                                       │
         │ ❱ 109 │   │   return self.me.show_collection                                                                                                                                                                                                               │
         │   110 │                                                                                                                                                                                                                                                    │
         │   111 │   @cached_property                                                                                                                                                                                                                                 │
         │   112 │   @flatten_list                                                                                                                                                                                                                                    │
         │                                                                                                                                                                                                                                                            │
         │ /home/elfie/.local/pipx/venvs/PlexTraktSync/lib/python3.8/site-packages/trakt/core.py:581 in inner                                                                                                                                                         │
         │                                                                                                                                                                                                                                                            │
         │   578 │   │   │   url, generator, _ = resp                                                                                                                                                                                                                 │
         │   579 │   │   │   json_data = self._handle_request('get', url)                                                                                                                                                                                             │
         │   580 │   │   │   try:                                                                                                                                                                                                                                     │
         │ ❱ 581 │   │   │   │   return generator.send(json_data)                                                                                                                                                                                                     │
         │   582 │   │   │   except StopIteration:                                                                                                                                                                                                                    │
         │   583 │   │   │   │   return None                                                                                                                                                                                                                          │
         │   584 │   │   return inner                                                                                                                                                                                                                                 │
         ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
         RuntimeError: generator raised StopIteration                                                                                                                                                                                                                  
Error: Error running clear_collections command: generator raised StopIteration

Expected behavior

That it would also clear the TV shows collection.

Inspect of problematic items

No response

Workarounds

No response

Config file contents

# Config File: /home/elfie/.config/PlexTraktSync/config.yml
cache:
  path: /home/elfie/.cache/PlexTraktSync/trakt_cache
excluded-libraries:
- Private
- Family Holidays
config:
  dotenv_override: true
plex:
  timeout: 300
logging:
  append: true
  console_time: false
  debug: false
  filename: plextraktsync.log
  filter_loggers: null
  filter: null
sync:
  rating_priority: plex
  plex_to_trakt:
    collection: true
    clear_collected: false
    ratings: true
    watched_status: true
    watchlist: true
  trakt_to_plex:
    liked_lists: true
    ratings: true
    watched_status: true
    watchlist: true
    watchlist_as_playlist: false
    playback_status: false
liked_lists:
  keep_watched: true
watch:
  add_collection: false
  remove_collection: false
  scrobble_threshold: 80
  username_filter: true
  media_progressbar: true
  ignore_clients: null
xbmc-providers:
  movies: imdb
  shows: tvdb

Install method

docker-compose

Version

0.31.7

Python Version

3.8.10

Plex Server Version

1.40.5.8854-f36c552fd

Operating System and Version

Alpine Linux 3.21.0

@glensc
Copy link
Collaborator

glensc commented Aug 26, 2024

Seems trakt.show_collection gets an error from trakt module:

like the show has no episodes? what is the show with the problem?

@lostandlost
Copy link

I am seeing similar errors when I run a 'sync' command. I tried updating to the most recent version and the error persists. Any thoughts on how to correct?

Traceback (most recent call last):
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\trakt\users.py", line 498, in show_collection
    te = next(e for e in ts.episodes if e.number == ep.get('number'))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\plextraktsync\cli.py", line 28, in wrap
    cmd(*args, **kwargs)
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\plextraktsync\commands\sync.py", line 74, in sync
    run_async(runner, walker=w, dry_run=config.dry_run)
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\plextraktsync\decorators\coro.py", line 15, in coro
    return asyncio.run(f(*args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\plextraktsync\commands\sync.py", line 13, in run_async
    await runner.sync(**kwargs)
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\plextraktsync\sync\Sync.py", line 55, in sync
    await pm.ahook.fini(walker=walker, dry_run=dry_run)
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\apluggy\wrap\ext.py", line 19, in call
    return await asyncio.gather(*coros)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\plextraktsync\sync\ClearCollectedPlugin.py", line 44, in fini
    self.clear_collected(self.trakt.episodes_collection, self.episode_trakt_ids, dry_run=dry_run)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\AppData\Local\Programs\Python\Python312\Lib\functools.py", line 995, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\plextraktsync\decorators\flatten.py", line 8, in flatten_list
    return list(method(*args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\plextraktsync\trakt\TraktApi.py", line 115, in episodes_collection
    for show in self.show_collection:
                ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\plextraktsync\decorators\rate_limit.py", line 20, in rate_limit
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\plextraktsync\decorators\retry.py", line 26, in retry
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\plextraktsync\trakt\TraktApi.py", line 110, in show_collection
    return self.me.show_collection
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXX\pipx\venvs\plextraktsync\Lib\site-packages\trakt\core.py", line 581, in inner
    return generator.send(json_data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: generator raised StopIteration

@lostandlost
Copy link

Well whatever the problem was, it seems to have fixed itself. I did a full sync just now and and it completed without issue.

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

3 participants