comparison libervia/backend/memory/sqla_mapping.py @ 4095:684ba556a617

core (memory/sqla_mapping): fix legacy pickled values: folloing packages refactoring, legacy pickled values could not be unpickled (due to use of old classes). This temporary workaround fix it, but the right thing to do will be to move from pickle to JSON at some point.
author Goffi <goffi@goffi.org>
date Mon, 12 Jun 2023 14:57:27 +0200
parents 4b842c1fb686
children 02f0adc745c6
comparison
equal deleted inserted replaced
4094:c3b68fdc2de7 4095:684ba556a617
100 try: 100 try:
101 value = value.encode() 101 value = value.encode()
102 except AttributeError: 102 except AttributeError:
103 pass 103 pass
104 # "utf-8" encoding is needed to handle Python 2 pickled data 104 # "utf-8" encoding is needed to handle Python 2 pickled data
105 return pickle.loads(value, encoding="utf-8") 105 try:
106 return pickle.loads(value, encoding="utf-8")
107 except ModuleNotFoundError:
108 # FIXME: workaround due to package renaming, need to move all pickle code to
109 # JSON
110 return pickle.loads(
111 value.replace(b"sat.plugins", b"libervia.backend.plugins"),
112 encoding="utf-8"
113 )
106 114
107 115
108 class Json(TypeDecorator): 116 class Json(TypeDecorator):
109 """Handle JSON field in DB independant way""" 117 """Handle JSON field in DB independant way"""
110 # Blob is used on SQLite but gives errors when used here, while Text works fine 118 # Blob is used on SQLite but gives errors when used here, while Text works fine