Only copy has_cover and id if they exist

This commit is contained in:
Kovid Goyal 2024-09-29 22:24:23 +05:30
parent c10a718174
commit 5b17a2431f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -7,6 +7,7 @@ __docformat__ = 'restructuredtext en'
import copy import copy
import traceback import traceback
from contextlib import suppress
from calibre import prints from calibre import prints
from calibre.constants import DEBUG from calibre.constants import DEBUG
@ -232,8 +233,10 @@ class Metadata:
m = Metadata(None) m = Metadata(None)
object.__setattr__(m, '_data', copy.deepcopy(object.__getattribute__(self, '_data'))) object.__setattr__(m, '_data', copy.deepcopy(object.__getattribute__(self, '_data')))
# Also copy these two top-level attributes as they can appear in templates. # Also copy these two top-level attributes as they can appear in templates.
object.__setattr__(m, 'id', copy.copy(self.get('id'))) with suppress(AttributeError):
object.__setattr__(m, 'has_cover', copy.copy(self.get('has_cover'))) object.__setattr__(m, 'id', copy.copy(self.__getattribute__('id')))
with suppress(AttributeError):
object.__setattr__(m, 'has_cover', copy.copy(self.__getattribute__('has_cover')))
return m return m
def get(self, field, default=None): def get(self, field, default=None):