snowflakedb/snowflake-sqlalchemy

SNOW-889293: Support `json_serializer` and `json_deserializer` engine/dialect paremeters

edgarrmondragon opened this issue · 1 comments

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

Seems like a legit feature, what do you think @sfc-gh-aling ?