The Error
Attempting to use PinotDB with SQL Alchemy produced the following error related to a missing _json_deserializer() method:
My relevant versions are pinotdb==0.4.13, and SQLAlchemy==2.0.2.
Traceback (most recent call last):
File "...sqlalchemy/sql/sqltypes.py", line 2714, in result_processor
json_deserializer = dialect._json_deserializer or json.loads
AttributeError: 'PinotDialect' object has no attribute '_json_deserializer'
The Fix
In all cases I've encountered, the object is already parsed (into a dict) and could be passed straight through (the file db.py calls json.loads() already). However, for type safety, I added an if/else statement to check to see whether the content is deserializable (is a string, byte array, or bytes). If it is, use the json.loads() method to parse it into a JSON. If the object is not deserializable, then it is simply returned (and presumed to be an already parsed dictionary). The resulting new function is
def _json_deserializer(self, content: any):
if isinstance(content, str) or isinstance(content, bytearray) or isinstance(content, bytes):
return json.loads(content)
else:
return content
The Error Attempting to use PinotDB with SQL Alchemy produced the following error related to a missing _json_deserializer() method:
My relevant versions are
pinotdb==0.4.13
, andSQLAlchemy==2.0.2
.The Fix In all cases I've encountered, the object is already parsed (into a dict) and could be passed straight through (the file
db.py
callsjson.loads()
already). However, for type safety, I added an if/else statement to check to see whether the content is deserializable (is a string, byte array, or bytes). If it is, use the json.loads() method to parse it into a JSON. If the object is not deserializable, then it is simply returned (and presumed to be an already parsed dictionary). The resulting new function is