newdb: Handle databases that have empty author records

Fixes #1218465 [Can not Edit Metadata](https://bugs.launchpad.net/calibre/+bug/1218465)
This commit is contained in:
Kovid Goyal 2013-08-30 17:25:59 +05:30
parent 5b1ba794b1
commit 6d667dbc8f
2 changed files with 2 additions and 6 deletions

View File

@ -1299,11 +1299,7 @@ class Cache(object):
string. ''' string. '''
table = self.fields['authors'].table table = self.fields['authors'].table
result = [] result = []
try: rmap = {icu_lower(v):k for k, v in table.id_map.iteritems()}
rmap = {icu_lower(v):k for k, v in table.id_map.iteritems()}
except AttributeError:
# Somehow, the authors table has some authors that are None. Corrupted db?
rmap = {icu_lower(v or ''):k for k, v in table.id_map.iteritems()}
for aut in authors: for aut in authors:
aid = rmap.get(icu_lower(aut), None) aid = rmap.get(icu_lower(aut), None)
result.append(author_to_author_sort(aut) if aid is None else table.asort_map[aid]) result.append(author_to_author_sort(aut) if aid is None else table.asort_map[aid])

View File

@ -56,7 +56,7 @@ class Table(object):
}.get(metadata['datatype'], None) }.get(metadata['datatype'], None)
if name == 'authors': if name == 'authors':
# Legacy # Legacy
self.unserialize = lambda x: x.replace('|', ',') if x else None self.unserialize = lambda x: x.replace('|', ',') if x else ''
self.link_table = (link_table if link_table else self.link_table = (link_table if link_table else
'books_%s_link'%self.metadata['table']) 'books_%s_link'%self.metadata['table'])