Catch StaleDataError

Update requirements jsonschema
This commit is contained in:
Ozzie Isaacs 2022-06-13 17:54:35 +02:00
parent f85b587d0a
commit 02e1be09df
3 changed files with 9 additions and 7 deletions

View File

@ -39,6 +39,7 @@ from flask_babel import lazy_gettext as N_
from flask_babel import get_locale from flask_babel import get_locale
from flask_login import current_user, login_required from flask_login import current_user, login_required
from sqlalchemy.exc import OperationalError, IntegrityError from sqlalchemy.exc import OperationalError, IntegrityError
from sqlalchemy.orm.exc import StaleDataError
from . import constants, logger, isoLanguages, gdriveutils, uploader, helper, kobo_sync_status from . import constants, logger, isoLanguages, gdriveutils, uploader, helper, kobo_sync_status
from . import config, ub, db, calibre_db from . import config, ub, db, calibre_db
@ -221,7 +222,7 @@ def edit_book(book_id):
calibre_db.session.rollback() calibre_db.session.rollback()
flash(str(e), category="error") flash(str(e), category="error")
return redirect(url_for('web.show_book', book_id=book.id)) return redirect(url_for('web.show_book', book_id=book.id))
except (OperationalError, IntegrityError) as e: except (OperationalError, IntegrityError, StaleDataError) as e:
log.error_or_exception("Database error: {}".format(e)) log.error_or_exception("Database error: {}".format(e))
calibre_db.session.rollback() calibre_db.session.rollback()
flash(_(u"Database error: %(error)s.", error=e.orig), category="error") flash(_(u"Database error: %(error)s.", error=e.orig), category="error")
@ -295,7 +296,7 @@ def upload():
else: else:
resp = {"location": url_for('web.show_book', book_id=book_id)} resp = {"location": url_for('web.show_book', book_id=book_id)}
return Response(json.dumps(resp), mimetype='application/json') return Response(json.dumps(resp), mimetype='application/json')
except (OperationalError, IntegrityError) as e: except (OperationalError, IntegrityError, StaleDataError) as e:
calibre_db.session.rollback() calibre_db.session.rollback()
log.error_or_exception("Database error: {}".format(e)) log.error_or_exception("Database error: {}".format(e))
flash(_(u"Database error: %(error)s.", error=e.orig), category="error") flash(_(u"Database error: %(error)s.", error=e.orig), category="error")
@ -443,7 +444,7 @@ def edit_list_book(param):
if param == 'title' and vals.get('checkT') == "false": if param == 'title' and vals.get('checkT') == "false":
book.sort = sort_param book.sort = sort_param
calibre_db.session.commit() calibre_db.session.commit()
except (OperationalError, IntegrityError) as e: except (OperationalError, IntegrityError, StaleDataError) as e:
calibre_db.session.rollback() calibre_db.session.rollback()
log.error_or_exception("Database error: {}".format(e)) log.error_or_exception("Database error: {}".format(e))
ret = Response(json.dumps({'success': False, ret = Response(json.dumps({'success': False,
@ -556,7 +557,7 @@ def table_xchange_author_title():
book.last_modified = datetime.utcnow() book.last_modified = datetime.utcnow()
try: try:
calibre_db.session.commit() calibre_db.session.commit()
except (OperationalError, IntegrityError) as e: except (OperationalError, IntegrityError, StaleDataError) as e:
calibre_db.session.rollback() calibre_db.session.rollback()
log.error_or_exception("Database error: %s", e) log.error_or_exception("Database error: %s", e)
return json.dumps({'success': False}) return json.dumps({'success': False})
@ -1190,7 +1191,7 @@ def upload_single_file(file_request, book, book_id):
calibre_db.session.add(db_format) calibre_db.session.add(db_format)
calibre_db.session.commit() calibre_db.session.commit()
calibre_db.update_title_sort(config) calibre_db.update_title_sort(config)
except (OperationalError, IntegrityError) as e: except (OperationalError, IntegrityError, StaleDataError) as e:
calibre_db.session.rollback() calibre_db.session.rollback()
log.error_or_exception("Database error: {}".format(e)) log.error_or_exception("Database error: {}".format(e))
flash(_(u"Database error: %(error)s.", error=e.orig), category="error") flash(_(u"Database error: %(error)s.", error=e.orig), category="error")

View File

@ -33,6 +33,7 @@ try:
except ImportError: except ImportError:
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.exc import OperationalError, InvalidRequestError, IntegrityError from sqlalchemy.exc import OperationalError, InvalidRequestError, IntegrityError
from sqlalchemy.orm.exc import StaleDataError
from sqlalchemy.sql.expression import text from sqlalchemy.sql.expression import text
try: try:
@ -318,7 +319,7 @@ def getFolderId(path, drive):
session.commit() session.commit()
else: else:
currentFolderId = storedPathName.gdrive_id currentFolderId = storedPathName.gdrive_id
except (OperationalError, IntegrityError) as ex: except (OperationalError, IntegrityError, StaleDataError) as ex:
log.error_or_exception('Database error: {}'.format(ex)) log.error_or_exception('Database error: {}'.format(ex))
session.rollback() session.rollback()
except ApiRequestError as ex: except ApiRequestError as ex:

View File

@ -41,4 +41,4 @@ natsort>=2.2.0,<8.2.0
comicapi>=2.2.0,<2.3.0 comicapi>=2.2.0,<2.3.0
# Kobo integration # Kobo integration
jsonschema>=3.2.0,<4.6.0 jsonschema>=3.2.0,<4.7.0