This is an automated email from the ASF dual-hosted git repository. beto pushed a commit to branch fix_get_sqla_engine in repository https://gitbox.apache.org/repos/asf/superset.git
commit 9412cf88b4bec1c4a01f535380b9f8e758fb9b08 Author: Beto Dealmeida <[email protected]> AuthorDate: Thu Aug 10 17:29:21 2023 -0700 Fix inspector --- superset/db_engine_specs/trino.py | 7 ++++--- superset/models/core.py | 5 ----- tests/integration_tests/celery_tests.py | 5 ++--- tests/integration_tests/charts/data/api_tests.py | 7 ++++--- tests/integration_tests/model_tests.py | 3 ++- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/superset/db_engine_specs/trino.py b/superset/db_engine_specs/trino.py index f05bd67ec3..c3bdccc775 100644 --- a/superset/db_engine_specs/trino.py +++ b/superset/db_engine_specs/trino.py @@ -86,9 +86,10 @@ class TrinoEngineSpec(PrestoBaseEngineSpec): } if database.has_view_by_name(table_name, schema_name): - metadata["view"] = database.inspector.get_view_definition( - table_name, schema_name - ) + with database.get_inspector_with_context() as inspector: + metadata["view"] = inspector.get_view_definition( + table_name, schema_name + ) return metadata diff --git a/superset/models/core.py b/superset/models/core.py index bf4651fed9..f59cd1159b 100755 --- a/superset/models/core.py +++ b/superset/models/core.py @@ -668,11 +668,6 @@ class Database( def safe_sqlalchemy_uri(self) -> str: return self.sqlalchemy_uri - @property - def inspector(self) -> Inspector: - with self.get_sqla_engine_with_context() as engine: - return sqla.inspect(engine) - @cache_util.memoized_func( key="db:{self.id}:schema:{schema}:table_list", cache=cache_manager.cache, diff --git a/tests/integration_tests/celery_tests.py b/tests/integration_tests/celery_tests.py index 8693a88887..29a1f7a66a 100644 --- a/tests/integration_tests/celery_tests.py +++ b/tests/integration_tests/celery_tests.py @@ -120,9 +120,8 @@ def drop_table_if_exists(table_name: str, table_type: CtasMethod) -> None: def quote_f(value: Optional[str]): if not value: return value - return get_example_database().inspector.engine.dialect.identifier_preparer.quote_identifier( - value - ) + with get_example_database().get_inspector_with_context() as inspector: + return inspector.engine.dialect.identifier_preparer.quote_identifier(value) def cta_result(ctas_method: CtasMethod): diff --git a/tests/integration_tests/charts/data/api_tests.py b/tests/integration_tests/charts/data/api_tests.py index da3a28f1ba..dc82026986 100644 --- a/tests/integration_tests/charts/data/api_tests.py +++ b/tests/integration_tests/charts/data/api_tests.py @@ -113,9 +113,10 @@ class BaseTestChartDataApi(SupersetTestCase): def quote_name(self, name: str): if get_main_database().backend in {"presto", "hive"}: - return get_example_database().inspector.engine.dialect.identifier_preparer.quote_identifier( - name - ) + with get_example_database().get_inspector_with_context() as inspector: # E: Ne + return inspector.engine.dialect.identifier_preparer.quote_identifier( + name + ) return name diff --git a/tests/integration_tests/model_tests.py b/tests/integration_tests/model_tests.py index 3a5f7c0a77..5222c1cb34 100644 --- a/tests/integration_tests/model_tests.py +++ b/tests/integration_tests/model_tests.py @@ -296,7 +296,8 @@ class TestDatabaseModel(SupersetTestCase): db = get_example_database() table_name = "energy_usage" sql = db.select_star(table_name, show_cols=False, latest_partition=False) - quote = db.inspector.engine.dialect.identifier_preparer.quote_identifier + with db.get_sqla_engine_with_context() as engine: + quote = engine.dialect.identifier_preparer.quote_identifier expected = ( textwrap.dedent( f"""\
