From 009fc9937a0d89c46d3f84de8e7418922e2a2040 Mon Sep 17 00:00:00 2001 From: croneter Date: Tue, 6 Nov 2018 20:33:05 +0100 Subject: [PATCH] Fix OperationalError when trying to wipe empty Plex DB --- resources/lib/utils.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 850fa043..38bd6965 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -526,16 +526,21 @@ def wipe_database(): from . import plex_db # First get the paths to all synced playlists playlist_paths = [] - with plex_db.PlexDB() as plexdb: - if plexdb.songs_have_been_synced(): - LOG.info('Detected that music has also been synced - wiping music') - music = True - else: - LOG.info('No music has been synced in the past - not wiping') - music = False - plexdb.cursor.execute('SELECT kodi_path FROM playlists') - for entry in plexdb.cursor: - playlist_paths.append(entry[0]) + try: + with plex_db.PlexDB() as plexdb: + if plexdb.songs_have_been_synced(): + LOG.info('Detected that music has also been synced - wiping music') + music = True + else: + LOG.info('No music has been synced in the past - not wiping') + music = False + plexdb.cursor.execute('SELECT kodi_path FROM playlists') + for entry in plexdb.cursor: + playlist_paths.append(entry[0]) + except OperationalError: + # Plex DB completely empty yet. Wipe existing Kodi music only if we + # expect to sync Plex music + music = settings('enableMusic') == 'true' kodidb_functions.wipe_dbs(music) plex_db.wipe() plex_db.initialize()