# Buggy code
def __init__(self, id):
    """
    Looks up movie on tvdb and creates a new database model for it.
    These instances should only be added to a session via `session.merge`.
    """
    self.id = id

    try:
        series = TVDBRequest().get("series/%s" % self.id)
    except requests.RequestException as e:
        raise LookupError("Error updating data from tvdb: %s" % e)

    self.id = series["id"]
    self.language = "en"
    self.last_updated = series["lastUpdated"]
    self.name = series["seriesName"]
    self.rating = float(series["siteRating"]) if series["siteRating"] else 0.0
    self.status = series["status"]
    self.runtime = int(series["runtime"]) if series["runtime"] else 0
    self.airs_time = series["airsTime"]
    self.airs_dayofweek = series["airsDayOfWeek"]
    self.content_rating = series["rating"]
    self.network = series["network"]
    self.overview = series["overview"]
    self.imdb_id = series["imdbId"]
    self.zap2it_id = series["zap2itId"]
    self.first_aired = series["firstAired"]
    self.expired = False
    self.aliases = series["aliases"]
    self._banner = series["banner"]

    genres = _get_db_genres(series["genre"])
    self._genres = [TVDBGenre(**g) for g in genres]

    # Actors and Posters are lazy populated
    self._actors = None
    self._posters = None


# Traceback (OperationalError)
2016-03-29 04:00 ERROR    lazy_lookup   nC_movie-HUN    Unhandled error in lazy lookup plugin
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/utils/lazy_dict.py", line 36, in __getitem__
func(self.store)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/metainfo/imdb_lookup.py", line 235, in lazy_loader
self.lookup(entry)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugin.py", line 124, in wrapped_func
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/utils/database.py", line 30, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/metainfo/imdb_lookup.py", line 356, in lookup
entry.update_using_map(self.field_map, movie)
File "/usr/local/lib/python2.7/dist-packages/flexget/entry.py", line 266, in update_using_map
v = value(source_item)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/metainfo/imdb_lookup.py", line 212, in <lambda>
'imdb_languages': lambda movie: [lang.language.name for lang in movie.languages],
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/attributes.py", line 237, in __get__
return self.impl.get(instance_state(instance), dict_)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/attributes.py", line 583, in get
value = self.callable_(state, passive)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/strategies.py", line 532, in _load_for_state
return self._emit_lazyload(session, state, ident_key, passive)
File "<string>", line 1, in <lambda>
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/strategies.py", line 602, in _emit_lazyload
result = q.all()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2588, in all
return list(self)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2736, in __iter__
return self._execute_and_instances(context)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2751, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 914, in execute
return meth(self, multiparams, params)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1010, in _execute_clauseelement
compiled_sql, distilled_params
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
context)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
exc_info
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 200, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
context)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 450, in do_execute
cursor.execute(statement, parameters)
OperationalError: (sqlite3.OperationalError) database is locked [SQL: u'SELECT imdb_movie_languages.movie_id AS imdb_movie_languages_movie_id, imdb_movie_languages.language_id AS imdb_movie_languages_language_id, imdb_movie_languages.prominence AS imdb_movie_languages_prominence \nFROM imdb_movie_languages \nWHERE ? = imdb_movie_languages.movie_id ORDER BY imdb_movie_languages.prominence'] [parameters: (1495,)]

# Fixed code
def __init__(self, tvdb_id):
    """
    Looks up movie on tvdb and creates a new database model for it.
    These instances should only be added to a session via `session.merge`.
    """
    self.id = tvdb_id

    try:
        series = TVDBRequest().get("series/%s" % self.id)
    except requests.RequestException as e:
        raise LookupError("Error updating data from tvdb: %s" % e)

    self.id = series["id"]
    self.language = "en"
    self.last_updated = series["lastUpdated"]
    self.name = series["seriesName"]
    self.rating = float(series["siteRating"]) if series["siteRating"] else 0.0
    self.status = series["status"]
    self.runtime = int(series["runtime"]) if series["runtime"] else 0
    self.airs_time = series["airsTime"]
    self.airs_dayofweek = series["airsDayOfWeek"]
    self.content_rating = series["rating"]
    self.network = series["network"]
    self.overview = series["overview"]
    self.imdb_id = series["imdbId"]
    self.zap2it_id = series["zap2itId"]
    self.first_aired = series["firstAired"]
    self.expired = False
    self.aliases = series["aliases"]
    self._banner = series["banner"]
    self._genres = (
        [TVDBGenre(id=name) for name in series["genre"]] if series["genre"] else []
    )

    # Actors and Posters are lazy populated
    self._actors = None
    self._posters = None