Repository: Flexget/Flexget

Issue:
Anilist plugin crashes when relations.yuna.moe is unreachable
```
2022-02-16 05:42:37 DEBUG    utils.requests anime           POSTing URL https://relations.yuna.moe/api/ids with args () and kwargs {'data': None, 'json': {'anilist': 114099}, 'timeout': 30}
2022-02-16 05:42:38 VERBOSE  anilist       anime           Couldn't fetch additional IDs: 502 Server Error: Bad Gateway for url: https://relations.yuna.moe/api/ids
2022-02-16 05:42:38 CRITICAL task          anime           BUG: Unhandled error in plugin configure_series: local variable 'ids' referenced before assignment
(...)
UnboundLocalError: local variable 'ids' referenced before assignment
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/flexget/task.py", line 547, in __run_plugin
    result = method(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/flexget/event.py", line 20, in __call__
    return self.func(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/flexget/components/series/configure_series.py", line 61, in on_task_prepare
    for entry in result:
  File "/usr/local/lib/python3.10/site-packages/flexget/utils/cached_input.py", line 231, in __iter__
    for item in self.iterable:
  File "/usr/local/lib/python3.10/site-packages/flexget/plugins/input/anilist.py", line 155, in on_task_input
    if not ids or not isinstance(ids, dict):
UnboundLocalError: local variable 'ids' referenced before assignment
```
Anilist plugin crashes when relations.yuna.moe is unreachable
```
2022-02-16 05:42:37 DEBUG    utils.requests anime           POSTing URL https://relations.yuna.moe/api/ids with args () and kwargs {'data': None, 'json': {'anilist': 114099}, 'timeout': 30}
2022-02-16 05:42:38 VERBOSE  anilist       anime           Couldn't fetch additional IDs: 502 Server Error: Bad Gateway for url: https://relations.yuna.moe/api/ids
2022-02-16 05:42:38 CRITICAL task          anime           BUG: Unhandled error in plugin configure_series: local variable 'ids' referenced before assignment
(...)
UnboundLocalError: local variable 'ids' referenced before assignment
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/flexget/task.py", line 547, in __run_plugin
    result = method(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/flexget/event.py", line 20, in __call__
    return self.func(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/flexget/components/series/configure_series.py", line 61, in on_task_prepare
    for entry in result:
  File "/usr/local/lib/python3.10/site-packages/flexget/utils/cached_input.py", line 231, in __iter__
    for item in self.iterable:
  File "/usr/local/lib/python3.10/site-packages/flexget/plugins/input/anilist.py", line 155, in on_task_input
    if not ids or not isinstance(ids, dict):
UnboundLocalError: local variable 'ids' referenced before assignment
```


Discussion:

Resolving patch:
diff --git a/flexget/plugins/input/anilist.py b/flexget/plugins/input/anilist.py
--- a/flexget/plugins/input/anilist.py
+++ b/flexget/plugins/input/anilist.py
@@ -144,6 +144,7 @@ def on_task_input(self, task, config):
                     ) or 'all' in selected_formats
 
                     if has_selected_type and has_selected_release_status:
+                        ids = {}
                         try:
                             ids = task.requests.post(
                                 'https://relations.yuna.moe/api/ids',
@@ -152,7 +153,7 @@ def on_task_input(self, task, config):
                             logger.debug(f'Additional IDs: {ids}')
                         except RequestException as e:
                             logger.verbose(f'Couldn\'t fetch additional IDs: {e}')
-                        if not ids or not isinstance(ids, dict):
+                        if not isinstance(ids, dict):
                             ids = {}
 
                         logger.debug(f'Anime Entry: {anime}')


Test patch: