diff --git a/cratedb_toolkit/sqlalchemy/patch.py b/cratedb_toolkit/sqlalchemy/patch.py deleted file mode 100644 index 78c89770..00000000 --- a/cratedb_toolkit/sqlalchemy/patch.py +++ /dev/null @@ -1,34 +0,0 @@ -import typing as t - -import sqlalchemy as sa - - -def patch_inspector(): - """ - When using `get_table_names()`, make sure the correct schema name gets used. - - Apparently, SQLAlchemy does not honor the `search_path` of the engine, when - using the inspector? - - FIXME: Bug in CrateDB SQLAlchemy dialect? - """ - - def get_effective_schema(engine: sa.Engine): - schema_name_raw = engine.url.query.get("schema") - schema_name = None - if isinstance(schema_name_raw, str): - schema_name = schema_name_raw - elif isinstance(schema_name_raw, tuple): - schema_name = schema_name_raw[0] - return schema_name - - from crate.client.sqlalchemy.dialect import CrateDialect - - get_table_names_dist = CrateDialect.get_table_names - - def get_table_names(self, connection: sa.Connection, schema: t.Optional[str] = None, **kw: t.Any) -> t.List[str]: - if schema is None: - schema = get_effective_schema(connection.engine) - return get_table_names_dist(self, connection=connection, schema=schema, **kw) - - CrateDialect.get_table_names = get_table_names # type: ignore diff --git a/cratedb_toolkit/util/database.py b/cratedb_toolkit/util/database.py index 73d3de94..556809ee 100644 --- a/cratedb_toolkit/util/database.py +++ b/cratedb_toolkit/util/database.py @@ -211,7 +211,7 @@ def import_csv_pandas( Import CSV data using pandas. """ import pandas as pd - from crate.client.sqlalchemy.support import insert_bulk + from sqlalchemy_cratedb.support import insert_bulk df = pd.read_csv(filepath) with self.engine.connect() as connection: @@ -234,7 +234,7 @@ def import_csv_dask( """ import dask.dataframe as dd import pandas as pd - from crate.client.sqlalchemy.support import insert_bulk + from sqlalchemy_cratedb.support import insert_bulk # Set a few defaults. npartitions = npartitions or os.cpu_count() diff --git a/pyproject.toml b/pyproject.toml index 814bb780..e632446e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,11 +90,10 @@ dependencies = [ "colorama<1", "colorlog", "crash", - "crate[sqlalchemy]>=0.34", "croud==1.8", 'importlib-metadata; python_version <= "3.7"', "python-dotenv<2", - "sqlalchemy", + "sqlalchemy-cratedb@ git+https://github.com/crate-workbench/sqlalchemy-cratedb.git@amo/fix-inspector", "sqlparse<0.5", ] [project.optional-dependencies] diff --git a/tests/sqlalchemy/test_patch.py b/tests/sqlalchemy/test_patch.py index 1ed51552..bb591310 100644 --- a/tests/sqlalchemy/test_patch.py +++ b/tests/sqlalchemy/test_patch.py @@ -1,6 +1,5 @@ import sqlalchemy as sa -from cratedb_toolkit.sqlalchemy import patch_inspector from tests.conftest import TESTDRIVE_DATA_SCHEMA @@ -32,7 +31,6 @@ def test_inspector_patched(database): This verifies that it still works, when it properly has been assigned to the `?schema=` connection string URL parameter. """ - patch_inspector() tablename = f'"{TESTDRIVE_DATA_SCHEMA}"."foobar"' inspector: sa.Inspector = sa.inspect(database.engine) database.run_sql(f"CREATE TABLE {tablename} AS SELECT 1")