From e5f754ed0ee96857bcdcb6d30d9ea93c16e23d5c Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 10 Jan 2021 15:02:04 +0100 Subject: [PATCH] improved session handling --- cps/db.py | 2 +- cps/editbooks.py | 14 +- cps/tasks/convert.py | 1 - test/Calibre-Web TestSummary_Linux.html | 596 +++++++++++++++--------- 4 files changed, 392 insertions(+), 221 deletions(-) diff --git a/cps/db.py b/cps/db.py index dbb90ff1..ea865f80 100644 --- a/cps/db.py +++ b/cps/db.py @@ -545,7 +545,7 @@ class CalibreDB(): backref='books')) cls.session_factory = scoped_session(sessionmaker(autocommit=False, - autoflush=False, + autoflush=True, bind=cls.engine)) for inst in cls.instances: inst.initSession() diff --git a/cps/editbooks.py b/cps/editbooks.py index 2c045500..1b1e13a2 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -31,7 +31,7 @@ from flask import Blueprint, request, flash, redirect, url_for, abort, Markup, R from flask_babel import gettext as _ from flask_login import current_user, login_required from sqlalchemy.exc import OperationalError, IntegrityError - +from sqlite3 import OperationalError as sqliteOperationalError from . import constants, logger, isoLanguages, gdriveutils, uploader, helper from . import config, get_locale, ub, db from . import calibre_db @@ -310,7 +310,6 @@ def delete_book(book_id, book_format, jsonResponse): def render_edit_book(book_id): - calibre_db.update_title_sort(config) cc = calibre_db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all() book = calibre_db.get_filtered_book(book_id, allow_show_archived=True) if not book: @@ -607,12 +606,19 @@ def upload_cover(request, book): @edit_required def edit_book(book_id): modif_date = False + + # create the function for sorting... + try: + calibre_db.update_title_sort(config) + except sqliteOperationalError as e: + log.debug_or_exception(e) + calibre_db.session.rollback() + # Show form if request.method != 'POST': return render_edit_book(book_id) - # create the function for sorting... - calibre_db.update_title_sort(config) + book = calibre_db.get_filtered_book(book_id, allow_show_archived=True) # Book not found diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py index 93f964f9..d3e74569 100644 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -123,7 +123,6 @@ class TaskConvert(CalibreTask): book=book_id, uncompressed_size=os.path.getsize(file_path + format_new_ext)) try: local_db.session.merge(new_format) - local_db.session.flush() local_db.session.commit() except SQLAlchemyError as e: local_db.session.rollback() diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index 027a3e46..5949373d 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
-

Start Time: 2021-01-02 07:53:24

+

Start Time: 2021-01-10 18:12:04

-

Stop Time: 2021-01-02 10:58:22

+

Stop Time: 2021-01-10 20:39:46

-

Duration: 2h 37 min

+

Duration: 1h 59 min

@@ -611,15 +611,15 @@ - + TestEbookConvertGDriveKepubify + 5 + 1 + 1 3 - 3 - 0 - 0 0 - Detail + Detail @@ -634,20 +634,126 @@ - +
TestEbookConvertGDriveKepubify - test_convert_only
- PASS + +
+ FAIL +
+ + + + - + + +
TestEbookConvertGDriveKepubify - test_convert_only
+ + +
+ ERROR +
+ + + + + + + + +
TestEbookConvertGDriveKepubify - test_convert_wrong_excecutable
- PASS + +
+ ERROR +
+ + + + + + + + + + +
TestEbookConvertGDriveKepubify - test_convert_wrong_excecutable
+ + +
+ ERROR +
+ + + + @@ -1190,11 +1296,11 @@ - + TestEditBooksOnGdrive 20 - 19 - 1 + 20 + 0 0 0 @@ -1339,33 +1445,11 @@ - +
TestEditBooksOnGdrive - test_edit_title
- -
- FAIL -
- - - - + PASS @@ -1509,13 +1593,13 @@ AssertionError: 'No Cover' != 'The camicdemo' - + TestSetupGdrive 1 + 0 + 0 1 0 - 0 - 0 Detail @@ -1523,11 +1607,39 @@ AssertionError: 'No Cover' != 'The camicdemo' - +
TestSetupGdrive - test_config_gdrive
- PASS + +
+ ERROR +
+ + + + @@ -1803,6 +1915,60 @@ AssertionError: 'No Cover' != 'The camicdemo' + + _ErrorHolder + 1 + 0 + 0 + 1 + 0 + + Detail + + + + + + + +
tearDownClass (test_ldap)
+ + +
+ ERROR +
+ + + + + + + + + TestLogging 7 @@ -1811,13 +1977,13 @@ AssertionError: 'No Cover' != 'The camicdemo' 0 1 - Detail + Detail - +
TestLogging - test_access_log_recover
@@ -1826,7 +1992,7 @@ AssertionError: 'No Cover' != 'The camicdemo' - +
TestLogging - test_debug_log
@@ -1835,7 +2001,7 @@ AssertionError: 'No Cover' != 'The camicdemo' - +
TestLogging - test_failed_login
@@ -1844,19 +2010,19 @@ AssertionError: 'No Cover' != 'The camicdemo' - +
TestLogging - test_failed_register
- SKIP + SKIP
-