SNOW-889293: Support `json_serializer` and `json_deserializer` engine/dialect paremeters
edgarrmondragon opened this issue · 1 comments
edgarrmondragon commented
What is the current behavior?
These parameters are not supported, causing engine creation which should work for a generic SQLAlchemy database, to fail:
import decimal
import json
import simplejson
import sqlalchemy
sqlalchemy.create_engine(
"<a SF sqlalchemy URL>",
echo=False,
json_serializer=lambda obj: simplejson.dumps(obj, use_decimal=True),
json_deserializer=lambda json_str: json.loads(json_str, parse_float=decimal.Decimal),
)
File "/venv/lib/python3.9/site-packages/sqlalchemy/engine/create.py", line 632, in create_engine
raise TypeError(
TypeError: Invalid argument(s) 'json_serializer','json_deserializer' sent to create_engine(), using configuration SnowflakeDialect/QueuePool/Engine. Please check that the keyword arguments are appropriate for this combination of components.
What is the desired behavior?
That these parameters are supported, given they are supported in all built-in SQLAlchemy dialects.
How would this improve snowflake-connector-python
?
Not in any way, AFAICT.
References, Other Background
This should be as simple as overriding the constructor of SnowflakeDialect
:
class SnowflakeDialect(default.DefaultDialect):
def __init__(self, json_deserializer=None, json_serializer=None, **kwargs):
default.DefaultDialect.__init__(self, **kwargs)
self._json_deserializer = json_deserializer
self._json_serializer = json_serializer
I can start working on a PR if the maintainers are interested.
See
- https://github.com/sqlalchemy/sqlalchemy/blob/f6c3b7c1bb1c2a3b4323a1e68aed77ee599a72b2/lib/sqlalchemy/dialects/sqlite/base.py#L1968-L1984
- https://github.com/sqlalchemy/sqlalchemy/blob/f6c3b7c1bb1c2a3b4323a1e68aed77ee599a72b2/lib/sqlalchemy/dialects/postgresql/base.py#L3032-L3043
- https://docs.sqlalchemy.org/en/14/core/engines.html#sqlalchemy.create_engine.params.json_deserializer
- https://docs.sqlalchemy.org/en/14/core/engines.html#sqlalchemy.create_engine.params.json_serializer
sfc-gh-sfan commented
Seems like a legit feature, what do you think @sfc-gh-aling ?