From 4daace586008229d876d0dc6747ea7fbc53c1e57 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 24 Aug 2013 08:28:48 +0530 Subject: [PATCH] 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) --- src/calibre/db/cache.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 7a6e040218..7ead59ac06 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -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)