diff --git a/cratedb_toolkit/sqlalchemy/__init__.py b/cratedb_toolkit/sqlalchemy/__init__.py index ebff58bb..6b9e2cde 100644 --- a/cratedb_toolkit/sqlalchemy/__init__.py +++ b/cratedb_toolkit/sqlalchemy/__init__.py @@ -1,2 +1 @@ -from .patch import patch_inspector from .polyfill import check_uniqueness_factory, polyfill_autoincrement, polyfill_refresh_after_dml, refresh_table diff --git a/cratedb_toolkit/sqlalchemy/patch.py b/cratedb_toolkit/sqlalchemy/patch.py index 838df632..dc027b0a 100644 --- a/cratedb_toolkit/sqlalchemy/patch.py +++ b/cratedb_toolkit/sqlalchemy/patch.py @@ -1,12 +1,9 @@ import calendar import datetime as dt import json -import typing as t from decimal import Decimal from uuid import UUID -import sqlalchemy as sa - try: import numpy as np @@ -15,40 +12,6 @@ has_numpy = False -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 - - try: - from sqlalchemy_cratedb import dialect - except ImportError: # pragma: nocover - from crate.client.sqlalchemy.dialect import CrateDialect as dialect - - get_table_names_dist = dialect.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) - - dialect.get_table_names = get_table_names # type: ignore - - def patch_encoder(): import crate.client.http diff --git a/pyproject.toml b/pyproject.toml index 35615795..1269dade 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,6 +90,7 @@ dependencies = [ "colorama<1", "colorlog", "crash", + "croud==1.8", "fastapi<0.105", 'importlib-metadata; python_version < "3.8"', 'importlib-resources; python_version < "3.9"', diff --git a/tests/sqlalchemy/test_patch.py b/tests/sqlalchemy/test_patch.py index 44ca4cf2..3eb9ab70 100644 --- a/tests/sqlalchemy/test_patch.py +++ b/tests/sqlalchemy/test_patch.py @@ -4,7 +4,6 @@ import pytest import sqlalchemy as sa -from cratedb_toolkit.sqlalchemy import patch_inspector from cratedb_toolkit.sqlalchemy.patch import CrateJsonEncoderWithNumPy from tests.conftest import TESTDRIVE_DATA_SCHEMA @@ -37,7 +36,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")