Skip to content

SNOW-743102: create_engine(f"snowflake://").dialect fails #386

@rooterkyberian

Description

@rooterkyberian

Please answer these questions before submitting your issue. Thanks!

  1. What version of Python are you using?

Python 3.11.2 (main, Feb 9 2023, 00:38:19) [GCC 10.2.1 20210110]

  1. What operating system and processor architecture are you using?

Linux-5.15.0-58-generic-x86_64-with-glibc2.31

  1. What are the component versions in the environment (pip freeze)?
snowflake-sqlalchemy==1.4.6
SQLAlchemy==1.4.46
  1. What did you do?

Minimal program to recreate error:

from sqlalchemy import create_engine
create_engine(f"snowflake://").dialect

Traceback:

    sa_dialect = create_engine(f"snowflake://").dialect
<string>:2: in create_engine
    ???
/usr/local/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py:375: in warned
    return fn(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/create.py:564: in create_engine
    (cargs, cparams) = dialect.create_connect_args(u)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <snowflake.sqlalchemy.snowdialect.SnowflakeDialect object at 0x7f92d117c3d0>, url = snowflake://

    def create_connect_args(self, url):
        opts = url.translate_connect_args(username="user")
        if "database" in opts:
            name_spaces = [unquote_plus(e) for e in opts["database"].split("/")]
            if len(name_spaces) == 1:
                pass
            elif len(name_spaces) == 2:
                opts["database"] = name_spaces[0]
                opts["schema"] = name_spaces[1]
            else:
                raise sa_exc.ArgumentError(
                    f"Invalid name space is specified: {opts['database']}"
                )
>       if ".snowflakecomputing.com" not in opts["host"] and not opts.get("port"):
E       KeyError: 'host'

/usr/local/lib/python3.11/site-packages/snowflake/sqlalchemy/snowdialect.py:209: KeyError

  1. What did you expect to see?

I expected to get dialect object without need to set a dummy host.
As a workaround I'm passing `f"{dialect}://dummy" in the mean time to create_engine.

Such workaround is not needed for other sqlalchemy dialects (tested against: "redshift", "postgresql", "mysql")

  1. Can you set logging to DEBUG and collect the logs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions