From 5cc00e504abe835421a8265fedc3f63d8dfeba13 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 31 Jan 2023 15:23:00 +0530 Subject: [PATCH] postadd plugins should not be called with None book_id when a dupe is found --- src/calibre/db/cache.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index d7ec79f238..17a7676a7e 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -2002,17 +2002,17 @@ class Cache: as per the simple duplicate detection heuristic used by :meth:`has_book`. ''' duplicates, ids = [], [] - fmt_map = {} for mi, format_map in books: book_id = self.create_book_entry(mi, add_duplicates=add_duplicates, apply_import_tags=apply_import_tags, preserve_uuid=preserve_uuid) if book_id is None: duplicates.append((mi, format_map)) else: + fmt_map = {} ids.append(book_id) - for fmt, stream_or_path in iteritems(format_map): + for fmt, stream_or_path in format_map.items(): if self.add_format(book_id, fmt, stream_or_path, dbapi=dbapi, run_hooks=run_hooks): fmt_map[fmt.lower()] = getattr(stream_or_path, 'name', stream_or_path) or '' - run_plugins_on_postadd(dbapi or self, book_id, fmt_map) + run_plugins_on_postadd(dbapi or self, book_id, fmt_map) return ids, duplicates @write_api