mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
newdb: set_metadata should not allow case changes
set_metadata() was allowing case changes for is_multiple fields, causing for instance, adding books to change the case of existing tags/authors/etc. In the old backend it was inconsistent, case changes were disallowed for most fields, but allowed for a few, for example, series.
This commit is contained in:
parent
f7250683a4
commit
f017da50aa
@ -1057,7 +1057,7 @@ class Cache(object):
|
||||
|
||||
@write_api
|
||||
def set_metadata(self, book_id, mi, ignore_errors=False, force_changes=False,
|
||||
set_title=True, set_authors=True):
|
||||
set_title=True, set_authors=True, allow_case_change=False):
|
||||
'''
|
||||
Set metadata for the book `id` from the `Metadata` object `mi`
|
||||
|
||||
@ -1078,13 +1078,13 @@ class Cache(object):
|
||||
except (AttributeError, TypeError):
|
||||
pass
|
||||
|
||||
def set_field(name, val, **kwargs):
|
||||
self._set_field(name, {book_id:val}, **kwargs)
|
||||
def set_field(name, val):
|
||||
self._set_field(name, {book_id:val}, do_path_update=False, allow_case_change=allow_case_change)
|
||||
|
||||
path_changed = False
|
||||
if set_title and mi.title:
|
||||
path_changed = True
|
||||
set_field('title', mi.title, do_path_update=False)
|
||||
set_field('title', mi.title)
|
||||
if set_authors:
|
||||
path_changed = True
|
||||
if not mi.authors:
|
||||
@ -1092,7 +1092,7 @@ class Cache(object):
|
||||
authors = []
|
||||
for a in mi.authors:
|
||||
authors += string_to_authors(a)
|
||||
set_field('authors', authors, do_path_update=False)
|
||||
set_field('authors', authors)
|
||||
|
||||
if path_changed:
|
||||
self._update_path({book_id})
|
||||
|
@ -420,6 +420,13 @@ class WritingTest(BaseTest):
|
||||
ae(nmi2.get_extra('#series'), 1.0)
|
||||
self.compare_metadata(nmi2, oldmi2, exclude={'last_modified', 'format_metadata', '#series_index'})
|
||||
|
||||
cache = self.init_cache(self.cloned_library)
|
||||
mi = cache.get_metadata(1)
|
||||
otags = mi.tags
|
||||
mi.tags = [x.upper() for x in mi.tags]
|
||||
cache.set_metadata(3, mi)
|
||||
self.assertEqual(set(otags), set(cache.field_for('tags', 3)), 'case changes should not be allowed in set_metadata')
|
||||
|
||||
# }}}
|
||||
|
||||
def test_conversion_options(self): # {{{
|
||||
@ -574,4 +581,3 @@ class WritingTest(BaseTest):
|
||||
cache.add_format(1, 'ADD', BytesIO(b'xxxx'))
|
||||
test_invalidate()
|
||||
# }}}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user