From eaed53e25b9c9c9cd437d2bcd6709830ccbc6577 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sat, 5 Sep 2020 18:23:14 +0200 Subject: [PATCH] Fix for author edit error (2 same sort_authors lead maybe to choose wrong one) --- cps/db.py | 9 ++++++--- cps/editbooks.py | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cps/db.py b/cps/db.py index 40ba1753e..2cf1d98ba 100644 --- a/cps/db.py +++ b/cps/db.py @@ -593,13 +593,16 @@ class CalibreDB(): sort_authors = entry.author_sort.split('&') authors_ordered = list() error = False + ids = [a.id for a in entry.authors] for auth in sort_authors: + results = self.session.query(Authors).filter(Authors.sort == auth.lstrip().strip()).all() # ToDo: How to handle not found authorname - result = self.session.query(Authors).filter(Authors.sort == auth.lstrip().strip()).first() - if not result: + if not len(results): error = True break - authors_ordered.append(result) + for r in results: + if r.id in ids: + authors_ordered.append(r) if not error: entry.authors = authors_ordered return entry diff --git a/cps/editbooks.py b/cps/editbooks.py index 1de44d988..602d8fc05 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -684,6 +684,7 @@ def edit_book(book_id): if modif_date: book.last_modified = datetime.utcnow() + calibre_db.session.merge(book) calibre_db.session.commit() if config.config_use_google_drive: gdriveutils.updateGdriveCalibreFromLocal()