Thanks to visit codestin.com
Credit goes to github.com

Skip to content

sqlalchemy.inspect.has_table ignores schema. #109

Closed
@cdcadman

Description

@cdcadman

It works if I pass the schema to create_engine and call has_table with no schema. I think this could be fixed by changing line 285 to reflect the schema here:

def has_table(self, connection, table_name, schema=None, **kwargs) -> bool:

Example python script:

import os
import sqlalchemy as sa

host = os.getenv("DATABRICKS_SERVER_HOSTNAME")
http_path = os.getenv("DATABRICKS_HTTP_PATH")
access_token = os.getenv("DATABRICKS_TOKEN")
catalog = os.getenv("DATABRICKS_CATALOG")

engine = sa.create_engine(f"databricks://token:{access_token}@{host}?http_path={http_path}&catalog={catalog}&schema=temp")
with engine.connect() as conn:
    conn.exec_driver_sql("drop table if exists chuck_test;")
    conn.exec_driver_sql("create table chuck_test (a int);")
    assert sa.inspect(conn).has_table("chuck_test")

engine = sa.create_engine(f"databricks://token:{access_token}@{host}?http_path={http_path}&catalog={catalog}")
with engine.connect() as conn:
    assert sa.inspect(conn).has_table("chuck_test", schema="temp")

Output:

Traceback (most recent call last):
  File "C:\temp\test_databricks.py", line 17, in <module>
    assert sa.inspect(conn).has_table("chuck_test", schema="temp")
AssertionError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions