Possible Fix for database crash after adding new format and accessing calibre database afterwards

This commit is contained in:
OzzieIsaacs 2020-09-05 10:24:32 +02:00
parent f825c5ae83
commit feacbe8ebd
2 changed files with 7 additions and 8 deletions

View File

@ -48,6 +48,7 @@ try:
except ImportError: except ImportError:
use_unidecode = False use_unidecode = False
Session = None
cc_exceptions = ['datetime', 'comments', 'composite', 'series'] cc_exceptions = ['datetime', 'comments', 'composite', 'series']
cc_classes = {} cc_classes = {}
@ -409,6 +410,7 @@ class CalibreDB():
def setup_db(self, config, app_db_path): def setup_db(self, config, app_db_path):
self.config = config self.config = config
self.dispose() self.dispose()
global Session
if not config.config_calibre_dir: if not config.config_calibre_dir:
config.invalidate() config.invalidate()
@ -506,7 +508,7 @@ class CalibreDB():
backref='books')) backref='books'))
Session = scoped_session(sessionmaker(autocommit=False, Session = scoped_session(sessionmaker(autocommit=False,
autoflush=False, autoflush=True,
bind=self.engine)) bind=self.engine))
self.session = Session() self.session = Session()
return True return True

View File

@ -53,6 +53,7 @@ class TaskConvert(CalibreTask):
def _convert_ebook_format(self): def _convert_ebook_format(self):
error_message = None error_message = None
local_session = db.Session()
file_path = self.file_path file_path = self.file_path
book_id = self.bookid book_id = self.bookid
format_old_ext = u'.' + self.settings['old_book_format'].lower() format_old_ext = u'.' + self.settings['old_book_format'].lower()
@ -92,17 +93,13 @@ class TaskConvert(CalibreTask):
new_format = db.Data(name=cur_book.data[0].name, new_format = db.Data(name=cur_book.data[0].name,
book_format=self.settings['new_book_format'].upper(), book_format=self.settings['new_book_format'].upper(),
book=book_id, uncompressed_size=os.path.getsize(file_path + format_new_ext)) book=book_id, uncompressed_size=os.path.getsize(file_path + format_new_ext))
cur_book.data.append(new_format)
try: try:
# db.session.merge(cur_book) local_session.merge(new_format)
calibre_db.session.commit() local_session.commit()
except SQLAlchemyError as e: except SQLAlchemyError as e:
calibre_db.session.rollback() local_session.rollback()
log.error("Database error: %s", e) log.error("Database error: %s", e)
return return
self.results['path'] = cur_book.path self.results['path'] = cur_book.path
self.results['title'] = cur_book.title self.results['title'] = cur_book.title
if config.config_use_google_drive: if config.config_use_google_drive: