py3: Fix sorting on one-one fields that can have None values

Fixes #1878388 [Private bug](https://bugs.launchpad.net/calibre/+bug/1878388)
This commit is contained in:
Kovid Goyal 2020-05-13 16:59:33 +05:30
parent e40834080e
commit 9c05bb0ff3
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -192,6 +192,13 @@ class OneToOneField(Field):
dk = self._default_sort_key dk = self._default_sort_key
sk = self._sort_key sk = self._sort_key
if sk is IDENTITY: 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:bcmg(book_id, dk)
return lambda book_id:sk(bcmg(book_id, dk)) return lambda book_id:sk(bcmg(book_id, dk))