diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index bb4ef5e18b..47e4c90c76 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -310,7 +310,8 @@ class DB(object): # Initialize database {{{ def __init__(self, library_path, default_prefs=None, read_only=False, - restore_all_prefs=False, progress_callback=lambda x, y:True): + restore_all_prefs=False, progress_callback=lambda x, y:True, + load_user_formatter_functions=True): try: if isbytestring(library_path): library_path = library_path.decode(filesystem_encoding) @@ -386,7 +387,8 @@ class DB(object): self.initialize_prefs(default_prefs, restore_all_prefs, progress_callback) self.initialize_custom_columns() self.initialize_tables() - load_user_template_functions(self.library_id, + if load_user_formatter_functions: + load_user_template_functions(self.library_id, self.prefs.get('user_template_functions', [])) def initialize_prefs(self, default_prefs, restore_all_prefs, progress_callback): # {{{ diff --git a/src/calibre/db/legacy.py b/src/calibre/db/legacy.py index 2be12f9653..6157ad1878 100644 --- a/src/calibre/db/legacy.py +++ b/src/calibre/db/legacy.py @@ -38,10 +38,12 @@ def cleanup_tags(tags): def create_backend( library_path, default_prefs=None, read_only=False, - progress_callback=lambda x, y:True, restore_all_prefs=False): + progress_callback=lambda x, y:True, restore_all_prefs=False, + load_user_formatter_functions=True): return DB(library_path, default_prefs=default_prefs, read_only=read_only, restore_all_prefs=restore_all_prefs, - progress_callback=progress_callback) + progress_callback=progress_callback, + load_user_formatter_functions=load_user_formatter_functions) class LibraryDatabase(object): @@ -67,7 +69,8 @@ class LibraryDatabase(object): backend = self.backend = create_backend(library_path, default_prefs=default_prefs, read_only=read_only, restore_all_prefs=restore_all_prefs, - progress_callback=progress_callback) + progress_callback=progress_callback, + load_user_formatter_functions=not is_second_db) cache = self.new_api = Cache(backend) cache.init() self.data = View(cache) diff --git a/src/calibre/gui2/actions/copy_to_library.py b/src/calibre/gui2/actions/copy_to_library.py index c9b01193e5..11f18bd0e6 100644 --- a/src/calibre/gui2/actions/copy_to_library.py +++ b/src/calibre/gui2/actions/copy_to_library.py @@ -396,11 +396,12 @@ class CopyToLibraryAction(InterfaceAction): # Open the new db so we can check the custom columns. We use only the # backend since we only need the custom column definitions, not the - # rest of the data in the db. + # rest of the data in the db. We also do not want the user defined + # formatter functions because loading them can poison the template cache global libraries_with_checked_columns from calibre.db.legacy import create_backend - newdb = create_backend(loc) + newdb = create_backend(loc, load_user_formatter_functions=False) continue_processing = True with closing(newdb):