postadd plugins should not be called with None book_id when a dupe is found

This commit is contained in:
Kovid Goyal 2023-01-31 15:23:00 +05:30
parent bd960fa84d
commit 5cc00e504a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -2002,14 +2002,14 @@ class Cache:
as per the simple duplicate detection heuristic used by :meth:`has_book`. as per the simple duplicate detection heuristic used by :meth:`has_book`.
''' '''
duplicates, ids = [], [] duplicates, ids = [], []
fmt_map = {}
for mi, format_map in books: 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) 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: if book_id is None:
duplicates.append((mi, format_map)) duplicates.append((mi, format_map))
else: else:
fmt_map = {}
ids.append(book_id) 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): 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 '<stream>' fmt_map[fmt.lower()] = getattr(stream_or_path, 'name', stream_or_path) or '<stream>'
run_plugins_on_postadd(dbapi or self, book_id, fmt_map) run_plugins_on_postadd(dbapi or self, book_id, fmt_map)