Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
edgarrmondragon opened this issue Aug 8, 2023 · 1 comment
Labels

Comments

@edgarrmondragon
Copy link

edgarrmondragon commented Aug 8, 2023

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

@github-actions github-actions bot changed the title Support json_serializer and json_deserializer engine/dialect paremeters SNOW-889293: Support json_serializer and json_deserializer engine/dialect paremeters Aug 8, 2023
@sfc-gh-sfan
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants