newdb: Allow sorting on ids

Fix regression that broke calibredb catalog when sorting on the id
field. Fixes #1216090 [calibredb catalog fails on sort_key - KeyError: 'id'](https://bugs.launchpad.net/calibre/+bug/1216090)
This commit is contained in:
Kovid Goyal 2013-08-24 08:28:48 +05:30
parent c5472fe489
commit 4daace5860

View File

@ -820,8 +820,11 @@ class Cache(object):
ans = self.fields[fm.get(field, field)].sort_keys_for_books(
get_metadata, lang_map, all_book_ids)
except KeyError:
ans = virtual_fields[fm.get(field, field)].sort_keys_for_books(
get_metadata, lang_map, all_book_ids)
if field == 'id':
ans = {bid:bid for bid in ids_to_sort}
else:
ans = virtual_fields[fm.get(field, field)].sort_keys_for_books(
get_metadata, lang_map, all_book_ids)
if is_series:
idx_ans = self.fields[idx].sort_keys_for_books(
get_metadata, lang_map, all_book_ids)