Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: RuntimeError: OrderedDict mutated during iteration

### INFO
**Python Version**: `3.6.7 (default, Oct 21 2018, 08:08:16) [GCC 8.2.0]`
**Operating System**: `Linux-4.9.35-v7+-armv7l-with-debian-buster-sid`
**Locale**: `UTF-8`
**Branch**: [develop](../tree/develop)
**Database**: `44.13`
**Commit**: pymedusa/Medusa@6bd26ddf43bb8c7be86aab31e808bf06168f9b3c
**Link to Log**: https://gist.github.com/6f1a413da4daf588d37b96eba10daf7f
### ERROR
<pre>
2019-01-22 00:25:25 ERROR    Thread_7 :: [6bd26dd] Exception generated: OrderedDict mutated during iteration
Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/medusa/server/web/core/base.py#L262">medusa/server/web/core/base.py</a>", line 262, in async_call
    result = function(**kwargs)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/medusa/server/web/home/handler.py#L2314">medusa/server/web/home/handler.py</a>", line 2314, in setSceneNumbering
    sceneSeason=sceneSeason, sceneEpisode=sceneEpisode
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/medusa/scene_numbering.py#L208">medusa/scene_numbering.py</a>", line 208, in set_scene_numbering
    series_obj.erase_cached_parse()
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/medusa/tv/series.py#L667">medusa/tv/series.py</a>", line 667, in erase_cached_parse
    NameParser().erase_cached_parse(self.indexer, self.series_id)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/medusa/name_parser/parser.py#L348">medusa/name_parser/parser.py</a>", line 348, in erase_cached_parse
    name_parser_cache.remove(indexer, indexer_id)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/medusa/name_parser/parser.py#L598">medusa/name_parser/parser.py</a>", line 598, in remove
    for item in to_remove:
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/medusa/name_parser/parser.py#L596">medusa/name_parser/parser.py</a>", line 596, in <genexpr>
    to_remove = (cached_name for cached_name, cached_parsed_result in iteritems(self.cache) if
RuntimeError: OrderedDict mutated during iteration
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:

Resolving patch:
diff --git a/medusa/name_parser/parser.py b/medusa/name_parser/parser.py
--- a/medusa/name_parser/parser.py
+++ b/medusa/name_parser/parser.py
@@ -593,10 +593,10 @@ def remove(self, indexer, indexer_id):
         """Remove cache item given indexer and indexer_id."""
         if not indexer or not indexer_id:
             return
-        to_remove = (cached_name for cached_name, cached_parsed_result in iteritems(self.cache) if
-                     cached_parsed_result.series.indexer == indexer and cached_parsed_result.series.indexerid == indexer_id)
+        to_remove = [cached_name for cached_name, cached_parsed_result in iteritems(self.cache) if
+                     cached_parsed_result.series.indexer == indexer and cached_parsed_result.series.indexerid == indexer_id]
         for item in to_remove:
-            self.cache.popitem(item)
+            del self.cache[item]
             log.debug('Removed parsed cached result for release: {release}'.format(release=item))
 
 


Test patch: