gurudesh/pytracebugs huggingface dataset:
# Buggy code
def load(cls, task=None):
    """Load all key/values from `task` into memory from database."""
    with Session() as session:
        for skv in (
            session.query(SimpleKeyValue).filter(SimpleKeyValue.task == task).all()
        ):
            cls.class_store[task][skv.plugin][skv.key] = skv.value


# Traceback (AttributeError)
2016-05-14 17:45 INFO     manager                       Database upgrade is required. Attempting now.
2016-05-14 17:45 ERROR    schema                        Failed to upgrade database for plugin simple_persistence: value
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/flexget/db_schema.py", line 150, in upgrade_wrapper
new_ver = upgrade_func(current_ver, session)
File "/usr/lib/python2.7/site-packages/flexget/utils/simple_persistence.py", line 42, in upgrade
for row in session.execute(select([table.c.id, table.c.plugin, table.c.key, table.c.value])):
File "/usr/lib/python2.7/site-packages/sqlalchemy/util/_collections.py", line 211, in __getattr__
raise AttributeError(key)
AttributeError: value
Traceback (most recent call last):
File "/usr/bin/flexget", line 11, in <module>
sys.exit(main())
File "/usr/lib/python2.7/site-packages/flexget/__init__.py", line 42, in main
manager.start()
File "/usr/lib/python2.7/site-packages/flexget/manager.py", line 309, in start
self.initialize()
File "/usr/lib/python2.7/site-packages/flexget/manager.py", line 206, in initialize
fire_event('manager.upgrade', self)
File "/usr/lib/python2.7/site-packages/flexget/event.py", line 106, in fire_event
result = event(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/flexget/event.py", line 23, in __call__
return self.func(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/flexget/db_schema.py", line 158, in upgrade_wrapper
manager.shutdown(finish_queue=False)
File "/usr/lib/python2.7/site-packages/flexget/manager.py", line 858, in shutdown
raise RuntimeError('Cannot shutdown manager that was never initialized.')
RuntimeError: Cannot shutdown manager that was never initialized.

# Fixed code
def load(cls, task=None):
    """Load all key/values from `task` into memory from database."""
    with Session() as session:
        for skv in (
            session.query(SimpleKeyValue).filter(SimpleKeyValue.task == task).all()
        ):
            try:
                cls.class_store[task][skv.plugin][skv.key] = skv.value
            except TypeError as e:
                log.warning(
                    "Value stored in simple_persistence cannot be decoded. It will be removed. Error: %s",
                    str(e),
                )
                cls.class_store[task][skv.plugin][skv.key] = DELETE
# Buggy code
def clean_value(name):
    # Move anything in leading brackets to the end
    # name = re.sub(r'^\[(.*?)\](.*)', r'\2 \1', name)

    for char in "[]()_,.":
        name = name.replace(char, " ")

    # if there are no spaces
    if name.find(" ") == -1:
        name = name.replace("-", " ")

    # remove unwanted words (imax, ..)
    # self.remove_words(data, self.remove)

    # MovieParser.strip_spaces
    name = " ".join(name.split())
    return name


# Traceback (TypeError)
2017-09-25 05:04 VERBOSE series Series_Collection_DE_Stream Found different quality for The.Fosters.S04E14-E20.German.DD+51.DL.1080p.AmazonHD.x264-TVS. Was 1080p h264 dd+5.1, overriding with$
2017-09-25 05:04 CRITICAL task Series_Collection_DE_Stream BUG: Unhandled error in plugin series: can only concatenate list (not "int") to list
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1514, in on_task_metainfo
self.parse_series(task.entries, series_name, series_config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1640, in parse_series
populate_entry_fields(entry, parsed, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1235, in populate_entry_fields
entry['series_id'] = parser.pack_identifier
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/parsers/parser_common.py", line 553, in pack_identifier
return 'S%02dE%02d-E%02d' % (self.season, self.episode, self.episode + self.episodes - 1)
TypeError: can only concatenate list (not "int") to list

# Fixed code
def clean_value(name):
    for char in "[]()_,.":
        name = name.replace(char, " ")

    # if there are no spaces
    if name.find(" ") == -1:
        name = name.replace("-", " ")

    # MovieParser.strip_spaces
    name = " ".join(name.split())
    return name
# Buggy code
def __init__(self, data, name, **kwargs):
    self._data = data
    self._name = name
    self._validated_name = None
    self._kwargs = kwargs


# Traceback (TypeError)
2017-09-25 05:04 VERBOSE series Series_Collection_DE_Stream Found different quality for The.Fosters.S04E14-E20.German.DD+51.DL.1080p.AmazonHD.x264-TVS. Was 1080p h264 dd+5.1, overriding with$
2017-09-25 05:04 CRITICAL task Series_Collection_DE_Stream BUG: Unhandled error in plugin series: can only concatenate list (not "int") to list
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1514, in on_task_metainfo
self.parse_series(task.entries, series_name, series_config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1640, in parse_series
populate_entry_fields(entry, parsed, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1235, in populate_entry_fields
entry['series_id'] = parser.pack_identifier
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/parsers/parser_common.py", line 553, in pack_identifier
return 'S%02dE%02d-E%02d' % (self.season, self.episode, self.episode + self.episodes - 1)
TypeError: can only concatenate list (not "int") to list

# Fixed code
def __init__(
    self,
    data=None,
    name=None,
    identified_by=None,
    id_type=None,
    id=None,
    episodes=1,
    season_pack=False,
    strict_name=False,
    quality=None,
    proper_count=0,
    special=False,
    group=None,
    valid=True,
):
    self.name = name
    self.data = data
    self.episodes = episodes
    self.season_pack = season_pack
    self.identified_by = identified_by
    self.id = id
    self.id_type = id_type
    self.quality = quality if quality is not None else Quality()
    self.proper_count = proper_count
    self.special = special
    self.group = group
    self.valid = valid
    self.strict_name = strict_name
# Buggy code
def __str__(self):
    return "<%s(name=%s,id=%s,season=%s,episode=%s,quality=%s,proper=%s,status=%s)>" % (
        self.__class__.__name__,
        self.name,
        self.id,
        self.season,
        self.episode,
        self.quality,
        self.proper_count,
        "OK" if self.valid else "INVALID",
    )


# Traceback (TypeError)
2017-09-25 05:04 VERBOSE series Series_Collection_DE_Stream Found different quality for The.Fosters.S04E14-E20.German.DD+51.DL.1080p.AmazonHD.x264-TVS. Was 1080p h264 dd+5.1, overriding with$
2017-09-25 05:04 CRITICAL task Series_Collection_DE_Stream BUG: Unhandled error in plugin series: can only concatenate list (not "int") to list
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1514, in on_task_metainfo
self.parse_series(task.entries, series_name, series_config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1640, in parse_series
populate_entry_fields(entry, parsed, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1235, in populate_entry_fields
entry['series_id'] = parser.pack_identifier
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/parsers/parser_common.py", line 553, in pack_identifier
return 'S%02dE%02d-E%02d' % (self.season, self.episode, self.episode + self.episodes - 1)
TypeError: can only concatenate list (not "int") to list

# Fixed code
def __str__(self):
    valid = "OK" if self.valid else "INVALID"
    return (
        "<SeriesParseResult(data=%s,name=%s,id=%s,season=%s,season_pack=%s,episode=%s,quality=%s,proper=%s,"
        "special=%s,status=%s)>"
        % (
            self.data,
            self.name,
            str(self.id),
            self.season,
            self.season_pack,
            self.episode,
            self.quality,
            self.proper_count,
            self.special,
            valid,
        )
    )
# Buggy code
def season(self):
    return 1 if not self.parsed_season and self.allow_seasonless else self.parsed_season


# Traceback (TypeError)
2017-09-25 05:04 VERBOSE series Series_Collection_DE_Stream Found different quality for The.Fosters.S04E14-E20.German.DD+51.DL.1080p.AmazonHD.x264-TVS. Was 1080p h264 dd+5.1, overriding with$
2017-09-25 05:04 CRITICAL task Series_Collection_DE_Stream BUG: Unhandled error in plugin series: can only concatenate list (not "int") to list
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1514, in on_task_metainfo
self.parse_series(task.entries, series_name, series_config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1640, in parse_series
populate_entry_fields(entry, parsed, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1235, in populate_entry_fields
entry['series_id'] = parser.pack_identifier
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/parsers/parser_common.py", line 553, in pack_identifier
return 'S%02dE%02d-E%02d' % (self.season, self.episode, self.episode + self.episodes - 1)
TypeError: can only concatenate list (not "int") to list

# Fixed code
def season(self):
    if self.id_type == "ep":
        return self.id[0]
    if self.id_type == "date":
        return self.id.year
    if self.id_type == "sequence":
        return 0
    return None
# Buggy code
def episode(self):
    raise NotImplementedError


# Traceback (TypeError)
2017-09-25 05:04 VERBOSE series Series_Collection_DE_Stream Found different quality for The.Fosters.S04E14-E20.German.DD+51.DL.1080p.AmazonHD.x264-TVS. Was 1080p h264 dd+5.1, overriding with$
2017-09-25 05:04 CRITICAL task Series_Collection_DE_Stream BUG: Unhandled error in plugin series: can only concatenate list (not "int") to list
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1514, in on_task_metainfo
self.parse_series(task.entries, series_name, series_config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1640, in parse_series
populate_entry_fields(entry, parsed, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1235, in populate_entry_fields
entry['series_id'] = parser.pack_identifier
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/parsers/parser_common.py", line 553, in pack_identifier
return 'S%02dE%02d-E%02d' % (self.season, self.episode, self.episode + self.episodes - 1)
TypeError: can only concatenate list (not "int") to list

# Fixed code
def episode(self):
    if self.id_type == "ep":
        return self.id[1]
    if self.id_type == "sequence":
        return self.id
    return None
# Buggy code
def identifiers(self):
    """Return all identifiers this parser represents. (for packs)"""
    # Currently 'ep' is the only id type that supports packs
    if not self.valid:
        raise Exception("Series flagged invalid")
    if self.id_type == "ep":
        return [
            "S%02dE%02d" % (self.season, self.episode + x) for x in range(self.episodes)
        ]
    elif self.id_type == "date":
        return [self.id.strftime("%Y-%m-%d")]
    if self.id is None:
        raise Exception("Series is missing identifier")
    else:
        return [self.id]


# Traceback (TypeError)
2017-09-25 05:04 VERBOSE series Series_Collection_DE_Stream Found different quality for The.Fosters.S04E14-E20.German.DD+51.DL.1080p.AmazonHD.x264-TVS. Was 1080p h264 dd+5.1, overriding with$
2017-09-25 05:04 CRITICAL task Series_Collection_DE_Stream BUG: Unhandled error in plugin series: can only concatenate list (not "int") to list
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1514, in on_task_metainfo
self.parse_series(task.entries, series_name, series_config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1640, in parse_series
populate_entry_fields(entry, parsed, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1235, in populate_entry_fields
entry['series_id'] = parser.pack_identifier
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/parsers/parser_common.py", line 553, in pack_identifier
return 'S%02dE%02d-E%02d' % (self.season, self.episode, self.episode + self.episodes - 1)
TypeError: can only concatenate list (not "int") to list

# Fixed code
def identifiers(self):
    """Return all identifiers this parser represents. (for packs)"""
    # Currently 'ep' is the only id type that supports packs
    if not self.valid:
        raise Exception("Series flagged invalid")
    if self.id_type == "ep":
        if self.season_pack:
            return ["S%02d" % self.season]
        return [
            "S%02dE%02d" % (self.season, self.episode + x) for x in range(self.episodes)
        ]
    elif self.id_type == "date":
        return [self.id.strftime("%Y-%m-%d")]
    if self.id is None:
        raise Exception("Series is missing identifier")
    else:
        return [self.id]
# Buggy code
def pack_identifier(self):
    """Return a combined identifier for the whole pack if this has more than one episode."""
    # Currently only supports ep mode
    if self.id_type == "ep" and self.episodes > 1:
        return "S%02dE%02d-E%02d" % (
            self.season,
            self.episode,
            self.episode + self.episodes - 1,
        )
    else:
        return self.identifier


# Traceback (TypeError)
2017-09-25 05:04 VERBOSE series Series_Collection_DE_Stream Found different quality for The.Fosters.S04E14-E20.German.DD+51.DL.1080p.AmazonHD.x264-TVS. Was 1080p h264 dd+5.1, overriding with$
2017-09-25 05:04 CRITICAL task Series_Collection_DE_Stream BUG: Unhandled error in plugin series: can only concatenate list (not "int") to list
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1514, in on_task_metainfo
self.parse_series(task.entries, series_name, series_config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1640, in parse_series
populate_entry_fields(entry, parsed, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1235, in populate_entry_fields
entry['series_id'] = parser.pack_identifier
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/parsers/parser_common.py", line 553, in pack_identifier
return 'S%02dE%02d-E%02d' % (self.season, self.episode, self.episode + self.episodes - 1)
TypeError: can only concatenate list (not "int") to list

# Fixed code
def pack_identifier(self):
    """Return a combined identifier for the whole pack if this has more than one episode."""
    # Currently only supports ep mode
    if self.id_type == "ep":
        if self.episodes > 1:
            return "S%02dE%02d-E%02d" % (
                self.season,
                self.episode,
                self.episode + self.episodes - 1,
            )
        else:
            return self.identifier
    else:
        return self.identifier
# Buggy code
def _guessit_options(self, options):
    settings = {
        "name_only": True,
        "allowed_languages": ["en", "fr"],
        "allowed_countries": ["us", "uk", "gb"],
    }
    # 'clean_function': clean_value
    options["episode_prefer_number"] = not options.get("identified_by") == "ep"
    if options.get("allow_groups"):
        options["expected_group"] = options["allow_groups"]
    if "date_yearfirst" in options:
        options["date_year_first"] = options["date_yearfirst"]
    if "date_dayfirst" in options:
        options["date_day_first"] = options["date_dayfirst"]
    settings.update(options)
    return settings


# Traceback (TypeError)
2017-09-25 05:04 VERBOSE series Series_Collection_DE_Stream Found different quality for The.Fosters.S04E14-E20.German.DD+51.DL.1080p.AmazonHD.x264-TVS. Was 1080p h264 dd+5.1, overriding with$
2017-09-25 05:04 CRITICAL task Series_Collection_DE_Stream BUG: Unhandled error in plugin series: can only concatenate list (not "int") to list
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1514, in on_task_metainfo
self.parse_series(task.entries, series_name, series_config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1640, in parse_series
populate_entry_fields(entry, parsed, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1235, in populate_entry_fields
entry['series_id'] = parser.pack_identifier
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/parsers/parser_common.py", line 553, in pack_identifier
return 'S%02dE%02d-E%02d' % (self.season, self.episode, self.episode + self.episodes - 1)
TypeError: can only concatenate list (not "int") to list

# Fixed code
def _guessit_options(options):
    settings = {
        "name_only": True,
        "allowed_languages": ["en", "fr"],
        "allowed_countries": ["us", "uk", "gb"],
    }
    # 'clean_function': clean_value
    options["episode_prefer_number"] = not options.get("identified_by") == "ep"
    if options.get("allow_groups"):
        options["expected_group"] = options["allow_groups"]
    if "date_yearfirst" in options:
        options["date_year_first"] = options["date_yearfirst"]
    if "date_dayfirst" in options:
        options["date_day_first"] = options["date_dayfirst"]
    else:
        # See https://github.com/guessit-io/guessit/issues/329
        # https://github.com/guessit-io/guessit/pull/333
        # They made changes that break backward compatibility, so we have to make do this hackery
        if options.get("date_year_first"):
            options["date_day_first"] = True
    settings.update(options)
    return settings
# Buggy code
def parse_movie(self, data, **kwargs):
    log.debug("Parsing movie: `%s` [options: %s]", data, kwargs)
    start = time.clock()
    guessit_options = self._guessit_options(kwargs)
    guessit_options["type"] = "movie"
    guess_result = guessit_api.guessit(data, options=guessit_options)
    # NOTE: Guessit expects str on PY3 and unicode on PY2 hence the use of future.utils.native
    parsed = GuessitParsedMovie(
        native(data), kwargs.pop("name", None), guess_result, **kwargs
    )
    end = time.clock()
    log.debug("Parsing result: %s (in %s ms)", parsed, (end - start) * 1000)
    return parsed


# Traceback (TypeError)
2017-09-25 05:04 VERBOSE series Series_Collection_DE_Stream Found different quality for The.Fosters.S04E14-E20.German.DD+51.DL.1080p.AmazonHD.x264-TVS. Was 1080p h264 dd+5.1, overriding with$
2017-09-25 05:04 CRITICAL task Series_Collection_DE_Stream BUG: Unhandled error in plugin series: can only concatenate list (not "int") to list
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1514, in on_task_metainfo
self.parse_series(task.entries, series_name, series_config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1640, in parse_series
populate_entry_fields(entry, parsed, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1235, in populate_entry_fields
entry['series_id'] = parser.pack_identifier
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/parsers/parser_common.py", line 553, in pack_identifier
return 'S%02dE%02d-E%02d' % (self.season, self.episode, self.episode + self.episodes - 1)
TypeError: can only concatenate list (not "int") to list

# Fixed code
def parse_movie(self, data, **kwargs):
    log.debug("Parsing movie: `%s` [options: %s]", data, kwargs)
    start = time.clock()
    guessit_options = self._guessit_options(kwargs)
    guessit_options["type"] = "movie"
    guess_result = guessit_api.guessit(data, options=guessit_options)
    # NOTE: Guessit expects str on PY3 and unicode on PY2 hence the use of future.utils.native
    parsed = MovieParseResult(
        data=data,
        name=guess_result.get("title"),
        year=guess_result.get("year"),
        proper_count=self._proper_count(guess_result),
        quality=self._quality(guess_result),
        release_group=guess_result.get("release_group"),
    )
    end = time.clock()
    log.debug("Parsing result: %s (in %s ms)", parsed, (end - start) * 1000)
    return parsed
# Buggy code
def parse_movie(self, data, **kwargs):
    log.debug("Parsing movie: `%s` kwargs: %s", data, kwargs)
    start = time.clock()
    parser = MovieParser()
    try:
        parser.parse(data)
    except ParseWarning as pw:
        log_once(pw.value, logger=log)
    end = time.clock()
    log.debug("Parsing result: %s (in %s ms)", parser, (end - start) * 1000)
    return parser


# Traceback (TypeError)
2017-09-25 05:04 VERBOSE series Series_Collection_DE_Stream Found different quality for The.Fosters.S04E14-E20.German.DD+51.DL.1080p.AmazonHD.x264-TVS. Was 1080p h264 dd+5.1, overriding with$
2017-09-25 05:04 CRITICAL task Series_Collection_DE_Stream BUG: Unhandled error in plugin series: can only concatenate list (not "int") to list
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1514, in on_task_metainfo
self.parse_series(task.entries, series_name, series_config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1640, in parse_series
populate_entry_fields(entry, parsed, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1235, in populate_entry_fields
entry['series_id'] = parser.pack_identifier
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/parsers/parser_common.py", line 553, in pack_identifier
return 'S%02dE%02d-E%02d' % (self.season, self.episode, self.episode + self.episodes - 1)
TypeError: can only concatenate list (not "int") to list

# Fixed code
def parse_movie(self, data, **kwargs):
    log.debug("Parsing movie: `%s` kwargs: %s", data, kwargs)
    start = time.clock()
    parser = MovieParser()
    try:
        parser.parse(data)
    except ParseWarning as pw:
        log_once(pw.value, logger=log)
    result = MovieParseResult(
        data=data,
        name=parser.name,
        year=parser.year,
        quality=parser.quality,
        proper_count=parser.proper_count,
    )
    end = time.clock()
    log.debug("Parsing result: %s (in %s ms)", parser, (end - start) * 1000)
    return result
# Buggy code
def parse_series(self, data, **kwargs):
    log.debug("Parsing series: `%s` kwargs: %s", data, kwargs)
    start = time.clock()
    parser = SeriesParser(**kwargs)
    try:
        parser.parse(data)
    except ParseWarning as pw:
        log_once(pw.value, logger=log)
    end = time.clock()
    log.debug("Parsing result: %s (in %s ms)", parser, (end - start) * 1000)
    return parser


# Traceback (TypeError)
2017-09-25 05:04 VERBOSE series Series_Collection_DE_Stream Found different quality for The.Fosters.S04E14-E20.German.DD+51.DL.1080p.AmazonHD.x264-TVS. Was 1080p h264 dd+5.1, overriding with$
2017-09-25 05:04 CRITICAL task Series_Collection_DE_Stream BUG: Unhandled error in plugin series: can only concatenate list (not "int") to list
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1514, in on_task_metainfo
self.parse_series(task.entries, series_name, series_config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1640, in parse_series
populate_entry_fields(entry, parsed, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1235, in populate_entry_fields
entry['series_id'] = parser.pack_identifier
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/parsers/parser_common.py", line 553, in pack_identifier
return 'S%02dE%02d-E%02d' % (self.season, self.episode, self.episode + self.episodes - 1)
TypeError: can only concatenate list (not "int") to list

# Fixed code
def parse_series(self, data, **kwargs):
    log.debug("Parsing series: `%s` kwargs: %s", data, kwargs)
    start = time.clock()
    parser = SeriesParser(**kwargs)
    try:
        parser.parse(data)
    except ParseWarning as pw:
        log_once(pw.value, logger=log)
    # TODO: Returning this invalid object seems a bit silly, raise an exception is probably better
    if not parser.valid:
        return SeriesParseResult(valid=False)
    result = SeriesParseResult(
        data=data,
        name=parser.name,
        episodes=parser.episodes,
        id=parser.id,
        id_type=parser.id_type,
        quality=parser.quality,
        proper_count=parser.proper_count,
        special=parser.special,
        group=parser.group,
        season_pack=parser.season_pack,
        strict_name=parser.strict_name,
        identified_by=parser.identified_by,
    )
    end = time.clock()
    log.debug("Parsing result: %s (in %s ms)", parser, (end - start) * 1000)
    return result
# Buggy code
def __str__(self):
    # for some fucking reason it's impossible to print self.field here, if someone figures out why please
    # tell me!
    valid = "INVALID"
    if self.valid:
        valid = "OK"
    return (
        "<SeriesParser(data=%s,name=%s,id=%s,season=%s,season_pack=%s,episode=%s,quality=%s,proper=%s,status=%s)>"
        % (
            self.data,
            self.name,
            str(self.id),
            self.season,
            self.season_pack,
            self.episode,
            self.quality,
            self.proper_count,
            valid,
        )
    )


# Traceback (TypeError)
2017-09-25 05:04 VERBOSE series Series_Collection_DE_Stream Found different quality for The.Fosters.S04E14-E20.German.DD+51.DL.1080p.AmazonHD.x264-TVS. Was 1080p h264 dd+5.1, overriding with$
2017-09-25 05:04 CRITICAL task Series_Collection_DE_Stream BUG: Unhandled error in plugin series: can only concatenate list (not "int") to list
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1514, in on_task_metainfo
self.parse_series(task.entries, series_name, series_config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1640, in parse_series
populate_entry_fields(entry, parsed, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/series.py", line 1235, in populate_entry_fields
entry['series_id'] = parser.pack_identifier
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/parsers/parser_common.py", line 553, in pack_identifier
return 'S%02dE%02d-E%02d' % (self.season, self.episode, self.episode + self.episodes - 1)
TypeError: can only concatenate list (not "int") to list

# Fixed code
def __str__(self):
    # for some fucking reason it's impossible to print self.field here, if someone figures out why please
    # tell me!
    valid = "INVALID"
    if self.valid:
        valid = "OK"
    return (
        "<SeriesParser(data=%s,name=%s,id=%s,season=%s,season_pack=%s,episode=%s,quality=%s,proper=%s,"
        "status=%s)>"
        % (
            self.data,
            self.name,
            str(self.id),
            self.season,
            self.season_pack,
            self.episode,
            self.quality,
            self.proper_count,
            valid,
        )
    )
# Buggy code
def __eq__(self, other):
    if isinstance(other, basestring):
        other = Quality(other)
        if not other:
            raise TypeError(
                "`%s` does not appear to be a valid quality string." % other.text
            )
    if not isinstance(other, Quality):
        if other is None:
            return False
        raise TypeError("Cannot compare %r and %r" % (self, other))
    return self._comparator == other._comparator


# Traceback (TypeError)
2017-11-29 20:34 CRITICAL task          task_name BUG: Unhandled error in plugin quality: `unknown` does not appear to be a valid quality string.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in __call__
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/quality.py", line 36, in on_task_filter
if not any(req.allows(entry['quality']) for req in reqs):
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/quality.py", line 36, in <genexpr>
if not any(req.allows(entry['quality']) for req in reqs):
File "/usr/local/lib/python2.7/dist-packages/flexget/utils/qualities.py", line 475, in allows
raise TypeError('`%s` does not appear to be a valid quality string.' % qual.text)
TypeError: `unknown` does not appear to be a valid quality string.

# Fixed code
def __eq__(self, other):
    if isinstance(other, basestring):
        other = Quality(other)
    if not isinstance(other, Quality):
        if other is None:
            return False
        raise TypeError("Cannot compare %r and %r" % (self, other))
    return self._comparator == other._comparator
# Buggy code
def __lt__(self, other):
    if isinstance(other, basestring):
        other = Quality(other)
        if not other:
            raise TypeError(
                "`%s` does not appear to be a valid quality string." % other.text
            )
    if not isinstance(other, Quality):
        raise TypeError("Cannot compare %r and %r" % (self, other))
    return self._comparator < other._comparator


# Traceback (TypeError)
2017-11-29 20:34 CRITICAL task          task_name BUG: Unhandled error in plugin quality: `unknown` does not appear to be a valid quality string.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in __call__
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/quality.py", line 36, in on_task_filter
if not any(req.allows(entry['quality']) for req in reqs):
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/quality.py", line 36, in <genexpr>
if not any(req.allows(entry['quality']) for req in reqs):
File "/usr/local/lib/python2.7/dist-packages/flexget/utils/qualities.py", line 475, in allows
raise TypeError('`%s` does not appear to be a valid quality string.' % qual.text)
TypeError: `unknown` does not appear to be a valid quality string.

# Fixed code
def __lt__(self, other):
    if isinstance(other, basestring):
        other = Quality(other)
    if not isinstance(other, Quality):
        raise TypeError("Cannot compare %r and %r" % (self, other))
    return self._comparator < other._comparator
# Buggy code
def allows(self, qual, loose=False):
    """Determine whether this set of requirements allows a given quality.

    :param Quality qual: The quality to evaluate.
    :param bool loose: If True, only ! (not) requirements will be enforced.
    :rtype: bool
    :returns: True if given quality passes all component requirements.
    """
    if isinstance(qual, basestring):
        qual = Quality(qual)
        if not qual:
            raise TypeError(
                "`%s` does not appear to be a valid quality string." % qual.text
            )
    for r_component, q_component in zip(self.components, qual.components):
        if not r_component.allows(q_component, loose=loose):
            return False
    return True


# Traceback (TypeError)
2017-11-29 20:34 CRITICAL task          task_name BUG: Unhandled error in plugin quality: `unknown` does not appear to be a valid quality string.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in __call__
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/quality.py", line 36, in on_task_filter
if not any(req.allows(entry['quality']) for req in reqs):
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/filter/quality.py", line 36, in <genexpr>
if not any(req.allows(entry['quality']) for req in reqs):
File "/usr/local/lib/python2.7/dist-packages/flexget/utils/qualities.py", line 475, in allows
raise TypeError('`%s` does not appear to be a valid quality string.' % qual.text)
TypeError: `unknown` does not appear to be a valid quality string.

# Fixed code
def allows(self, qual, loose=False):
    """Determine whether this set of requirements allows a given quality.

    :param Quality qual: The quality to evaluate.
    :param bool loose: If True, only ! (not) requirements will be enforced.
    :rtype: bool
    :returns: True if given quality passes all component requirements.
    """
    if isinstance(qual, basestring):
        qual = Quality(qual)
    for r_component, q_component in zip(self.components, qual.components):
        if not r_component.allows(q_component, loose=loose):
            return False
    return True
# Buggy code
def _update_search_strings(series, session, search=None):
    search_strings = series.search_strings
    add = (
        [series.name.lower()]
        + ([a.lower() for a in series.aliases] if series.aliases else [])
        + [search.lower()]
        if search
        else []
    )
    for name in set(add):
        if name not in search_strings:
            search_result = (
                session.query(TVDBSearchResult)
                .filter(TVDBSearchResult.search == name)
                .first()
            )
            if not search_result:
                search_result = TVDBSearchResult(search=name)
            search_result.series_id = series.id
            session.add(search_result)


# Traceback (AttributeError)
2017-09-24 22:18 ERROR    lazy_lookup   fetch-series    Unhandled error in lazy lookup plugin
Traceback (most recent call last):
File "c:\python27\lib\site-packages\flexget\utils\lazy_dict.py", line 37, in __getitem__
func(self.store)
File "c:\python27\lib\site-packages\flexget\plugins\metainfo\thetvdb_lookup.py", line 125, in lazy_series_lookup
return self.series_lookup(entry, language, self.series_map)
File "c:\python27\lib\site-packages\flexget\utils\database.py", line 34, in wrapper
return func(*args, **kwargs)
File "c:\python27\lib\site-packages\flexget\plugins\metainfo\thetvdb_lookup.py", line 117, in series_lookup
session=session
File "c:\python27\lib\site-packages\flexget\utils\database.py", line 31, in wrapper
return func(*args, **kwargs)
File "c:\python27\lib\site-packages\flexget\plugins\internal\api_tvdb.py", line 529, in lookup_series
_update_search_strings(series, session, search=name)
File "c:\python27\lib\site-packages\flexget\plugins\internal\api_tvdb.py", line 476, in _update_search_strings
search.lower()] if search else []
AttributeError: 'NoneType' object has no attribute 'lower'

# Fixed code
def _update_search_strings(series, session, search=None):
    search_strings = series.search_strings
    aliases = [a.lower() for a in series.aliases] if series.aliases else []
    searches = [search.lower()] if search else []
    add = [series.name.lower()] + aliases + searches
    for name in set(add):
        if name not in search_strings:
            search_result = (
                session.query(TVDBSearchResult)
                .filter(TVDBSearchResult.search == name)
                .first()
            )
            if not search_result:
                search_result = TVDBSearchResult(search=name)
            search_result.series_id = series.id
            session.add(search_result)
# Buggy code
def _parse_date(self, date_text):
    date_match = date_regex.search(date_text)
    days_ago_match = days_ago_regex.search(date_text)
    first_word = date_text.split(" ")[0].lower().strip()

    if first_word in ["vandaag", "vanochtend", "vanmiddag", "vanavond"]:
        return date.today()
    elif first_word == "gisteren":
        return date.today() - timedelta(days=1)
    elif first_word == "eergisteren":
        return date.today() - timedelta(days=2)
    elif first_word == "kijk":
        return None
    elif date_match:
        day = int(date_match.group(1))
        month = months.index(date_match.group(2)) + 1
        year = date_match.group(3)
        if year is None:
            year = date.today().year
        else:
            year = int(year)
        return date(year, month, day)
    elif days_ago_match:
        days_ago = int(days_ago_match.group(1))
        return date.today() - timedelta(days=days_ago)
    else:
        log.error("Cannot understand date '%s'", date_text)
        return date.today()


# Traceback (AttributeError)
2017-07-05 20:31 CRITICAL task tv-journaal BUG: Unhandled error in plugin npo_watchlist: 'NoneType' object has no attribute 'find'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/input/npo_watchlist.py", line 326, in on_task_input
entries += self._get_favorites_entries(task, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/input/npo_watchlist.py", line 318, in _get_favorites_entries
series_info = self._get_series_info(task, config, series_name, url)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/input/npo_watchlist.py", line 180, in _get_series_info
series_info['npo_url'] = tvseries.find('a', itemprop='url')['href']
AttributeError: 'NoneType' object has no attribute 'find'

# Fixed code
def _parse_date(self, date_text):
    return datetime.strptime(date_text, "%d-%m-%Y").date()
# Buggy code
def _get_page(self, task, config, url):
    login_response = requests.get(url)
    if login_response.url == url:
        log.debug("Already logged in")
        return login_response
    elif login_response.url != "https://mijn.npo.nl/inloggen":
        raise plugin.PluginError("Unexpected login page: {}".format(login_response.url))

    login_page = get_soup(login_response.content)
    token = login_page.find("input", attrs={"name": "authenticity_token"})["value"]

    email = config.get("email")
    password = config.get("password")

    try:
        profile_response = requests.post(
            "https://mijn.npo.nl/sessions",
            {"authenticity_token": token, "email": email, "password": password},
        )
    except requests.RequestException as e:
        raise plugin.PluginError("Request error: %s" % e.args[0])

    if profile_response.url == "https://mijn.npo.nl/sessions":
        raise plugin.PluginError("Failed to login. Check username and password.")
    elif profile_response.url != url:
        raise plugin.PluginError(
            "Unexpected page: {} (expected {})".format(profile_response.url, url)
        )

    return profile_response


# Traceback (AttributeError)
2017-07-05 20:31 CRITICAL task tv-journaal BUG: Unhandled error in plugin npo_watchlist: 'NoneType' object has no attribute 'find'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/input/npo_watchlist.py", line 326, in on_task_input
entries += self._get_favorites_entries(task, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/input/npo_watchlist.py", line 318, in _get_favorites_entries
series_info = self._get_series_info(task, config, series_name, url)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/input/npo_watchlist.py", line 180, in _get_series_info
series_info['npo_url'] = tvseries.find('a', itemprop='url')['href']
AttributeError: 'NoneType' object has no attribute 'find'

# Fixed code
def _get_page(self, task, config, url):
    self._login(task, config)

    try:
        page_response = requests.get(url)
        if page_response.url != url:
            raise plugin.PluginError(
                "Unexpected page: {} (expected {})".format(page_response.url, url)
            )

        return page_response
    except RequestException as e:
        raise plugin.PluginError("Request error: %s" % e.args[0])
# Buggy code
def _get_watchlist_entries(self, task, config):
    email = config.get("email")
    log.info("Retrieving npo.nl episode watchlist for %s", email)

    response = self._get_page(task, config, "https://mijn.npo.nl/profiel/kijklijst")
    page = get_soup(response.content)

    self.csrf_token = page.find("meta", attrs={"name": "csrf-token"})["content"]

    entries = list()
    for list_item in page.findAll("div", class_="watch-list-item"):
        url = list_item.find("a")["href"]
        series_name = next(list_item.find("h3").stripped_strings)
        remove_url = list_item.find("a", class_="unwatch-confirm")["href"]
        entry_date = self._parse_date(
            list_item.find("span", class_="global__content-info").text
        )

        episode_id = url.split("/")[-1]
        title = "{} ({})".format(series_name, episode_id)

        e = Entry()
        e["url"] = self._prefix_url("https://mijn.npo.nl", url)
        e["title"] = title
        e["series_name"] = series_name
        e["series_name_plain"] = self._convert_plain(series_name)
        e["series_date"] = entry_date
        e["series_id_type"] = "date"
        e["description"] = list_item.find("p").text
        e["remove_url"] = self._prefix_url("https://mijn.npo.nl", remove_url)

        if config.get("remove_accepted"):
            e.on_complete(self.entry_complete, task=task)

        entries.append(e)

    return entries


# Traceback (AttributeError)
2017-07-05 20:31 CRITICAL task tv-journaal BUG: Unhandled error in plugin npo_watchlist: 'NoneType' object has no attribute 'find'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/input/npo_watchlist.py", line 326, in on_task_input
entries += self._get_favorites_entries(task, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/input/npo_watchlist.py", line 318, in _get_favorites_entries
series_info = self._get_series_info(task, config, series_name, url)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/input/npo_watchlist.py", line 180, in _get_series_info
series_info['npo_url'] = tvseries.find('a', itemprop='url')['href']
AttributeError: 'NoneType' object has no attribute 'find'

# Fixed code
def _get_watchlist_entries(self, task, config, page):
    watchlist = page.find("div", attrs={"id": "component-grid-watchlist"})
    return self._parse_tiles(task, config, watchlist)