From 9c05bb0ff3dfdc2e4e64249b2a4d29912daf5a88 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 13 May 2020 16:59:33 +0530 Subject: [PATCH] py3: Fix sorting on one-one fields that can have None values Fixes #1878388 [Private bug](https://bugs.launchpad.net/calibre/+bug/1878388) --- src/calibre/db/fields.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/calibre/db/fields.py b/src/calibre/db/fields.py index 5ef970dbb3..ec82a90b7b 100644 --- a/src/calibre/db/fields.py +++ b/src/calibre/db/fields.py @@ -192,6 +192,13 @@ class OneToOneField(Field): dk = self._default_sort_key sk = self._sort_key if sk is IDENTITY: + if dk is not None: + def none_safe_key(book_id): + ans = bcmg(book_id, dk) + if ans is None: + ans = dk + return ans + return none_safe_key return lambda book_id:bcmg(book_id, dk) return lambda book_id:sk(bcmg(book_id, dk))