From 4f5764b1a81b154cf1dcbcb0e6f34d9a28f8a2d7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 22 Jul 2013 12:20:52 +0530 Subject: [PATCH] Handle undecodable bytes in text columns --- src/calibre/db/tables.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/calibre/db/tables.py b/src/calibre/db/tables.py index f71abe2a6d..34de470090 100644 --- a/src/calibre/db/tables.py +++ b/src/calibre/db/tables.py @@ -52,10 +52,16 @@ class Table(object): self.name, self.metadata = name, metadata self.sort_alpha = metadata.get('is_multiple', False) and metadata.get('display', {}).get('sort_alpha', False) + text = lambda x:x.decode('utf-8', 'replace') if isinstance(x, bytes) else x + # self.unserialize() maps values from the db to python objects self.unserialize = \ { 'datetime': _c_convert_timestamp, + 'text': text, + 'comments': text, + 'series': text, + 'enumeration': text, 'bool': bool }.get( metadata['datatype'], lambda x: x)