From 02e1be09df667c41ff8f9f775047c921b55d0589 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Mon, 13 Jun 2022 17:54:35 +0200 Subject: [PATCH] Catch StaleDataError Update requirements jsonschema --- cps/editbooks.py | 11 ++++++----- cps/gdriveutils.py | 3 ++- optional-requirements.txt | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index d3615050..0e7588ea 100755 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -39,6 +39,7 @@ from flask_babel import lazy_gettext as N_ from flask_babel import get_locale from flask_login import current_user, login_required 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 config, ub, db, calibre_db @@ -221,7 +222,7 @@ def edit_book(book_id): calibre_db.session.rollback() flash(str(e), category="error") 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)) calibre_db.session.rollback() flash(_(u"Database error: %(error)s.", error=e.orig), category="error") @@ -295,7 +296,7 @@ def upload(): else: resp = {"location": url_for('web.show_book', book_id=book_id)} return Response(json.dumps(resp), mimetype='application/json') - except (OperationalError, IntegrityError) as e: + except (OperationalError, IntegrityError, StaleDataError) as e: calibre_db.session.rollback() log.error_or_exception("Database error: {}".format(e)) 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": book.sort = sort_param calibre_db.session.commit() - except (OperationalError, IntegrityError) as e: + except (OperationalError, IntegrityError, StaleDataError) as e: calibre_db.session.rollback() log.error_or_exception("Database error: {}".format(e)) ret = Response(json.dumps({'success': False, @@ -556,7 +557,7 @@ def table_xchange_author_title(): book.last_modified = datetime.utcnow() try: calibre_db.session.commit() - except (OperationalError, IntegrityError) as e: + except (OperationalError, IntegrityError, StaleDataError) as e: calibre_db.session.rollback() log.error_or_exception("Database error: %s", e) 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.commit() calibre_db.update_title_sort(config) - except (OperationalError, IntegrityError) as e: + except (OperationalError, IntegrityError, StaleDataError) as e: calibre_db.session.rollback() log.error_or_exception("Database error: {}".format(e)) flash(_(u"Database error: %(error)s.", error=e.orig), category="error") diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index e2e0a536..866defaa 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -33,6 +33,7 @@ try: except ImportError: from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.exc import OperationalError, InvalidRequestError, IntegrityError +from sqlalchemy.orm.exc import StaleDataError from sqlalchemy.sql.expression import text try: @@ -318,7 +319,7 @@ def getFolderId(path, drive): session.commit() else: currentFolderId = storedPathName.gdrive_id - except (OperationalError, IntegrityError) as ex: + except (OperationalError, IntegrityError, StaleDataError) as ex: log.error_or_exception('Database error: {}'.format(ex)) session.rollback() except ApiRequestError as ex: diff --git a/optional-requirements.txt b/optional-requirements.txt index a0384bcd..97f355f2 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -41,4 +41,4 @@ natsort>=2.2.0,<8.2.0 comicapi>=2.2.0,<2.3.0 # Kobo integration -jsonschema>=3.2.0,<4.6.0 +jsonschema>=3.2.0,<4.7.0