diff --git a/gramps/gen/db/cursor.py b/gramps/gen/db/cursor.py index 7a552e7d4..1e7daeeb5 100644 --- a/gramps/gen/db/cursor.py +++ b/gramps/gen/db/cursor.py @@ -111,7 +111,11 @@ class BsddbBaseCursor(object): _flags | flags | (db.DB_RMW if self._update else 0), **kwargs) - return (data[0], loads(data[1])) if data else None + try: + return (data[0], loads(data[1])) if data else None + except UnicodeDecodeError: + #we need to assume we opened data in python3 saved in python2 + return (data[0], loads(data[1], encoding='utf-8')) if data else None return get diff --git a/gramps/gen/db/read.py b/gramps/gen/db/read.py index c96349d6f..c8aab4abd 100644 --- a/gramps/gen/db/read.py +++ b/gramps/gen/db/read.py @@ -1536,6 +1536,10 @@ class DbBsddbRead(DbReadBase, Callback): handle = handle.encode('utf-8') try: return table.get(handle, txn=self.txn) + except UnicodeDecodeError: + #we need to assume we opened data in python3 saved in python2 + raw = table.db.get(handle, txn=self.txn) + return pickle.loads(raw, encoding='utf-8') except DBERRS as msg: self.__log_error() raise DbError(msg) diff --git a/gramps/gen/db/write.py b/gramps/gen/db/write.py index 642ba118b..f502b4cee 100644 --- a/gramps/gen/db/write.py +++ b/gramps/gen/db/write.py @@ -648,7 +648,13 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): pass # bookmarks - meta = lambda meta: self.metadata.get(meta, default=[]) + def meta(key): + try: + return self.metadata.get(key, default=[]) + except UnicodeDecodeError: + #we need to assume we opened data in python3 saved in python2 + raw = self.metadata.db.get(key, default=[]) + return pickle.loads(raw, encoding='utf-8') if raw else raw self.bookmarks.set(meta(b'bookmarks')) self.family_bookmarks.set(meta(b'family_bookmarks')) @@ -1800,6 +1806,10 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): handle = handle.encode('utf-8') try: data = data_map.get(handle, txn=self.txn) + except UnicodeDecodeError: + #we need to assume we opened data in python3 saved in python2 + raw = data_map.db.get(handle, txn=self.txn) + data = pickle.loads(raw, encoding='utf-8') except: data = None # under certain circumstances during a database reload,