From f017da50aaa933b9a7cdcd55272045894980315d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 12 Aug 2013 18:53:22 +0530 Subject: [PATCH] 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. --- src/calibre/db/cache.py | 10 +++++----- src/calibre/db/tests/writing.py | 8 +++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 2dc5d557f7..7ed653093c 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -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}) diff --git a/src/calibre/db/tests/writing.py b/src/calibre/db/tests/writing.py index 19f6e70f48..f4b8553164 100644 --- a/src/calibre/db/tests/writing.py +++ b/src/calibre/db/tests/writing.py @@ -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() # }}} -