Skip to content

Commit

Permalink
Fix inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Aug 11, 2023
1 parent c5fe359 commit 9412cf8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
7 changes: 4 additions & 3 deletions superset/db_engine_specs/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ def extra_table_metadata(
}

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(

Check warning on line 90 in superset/db_engine_specs/trino.py

View check run for this annotation

Codecov / codecov/patch

superset/db_engine_specs/trino.py#L89-L90

Added lines #L89 - L90 were not covered by tests
table_name, schema_name
)

return metadata

Expand Down
5 changes: 0 additions & 5 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,11 +668,6 @@ def apply_limit_to_sql(
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,
Expand Down
5 changes: 2 additions & 3 deletions tests/integration_tests/celery_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions tests/integration_tests/charts/data/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ def get_expected_row_count(self, client_id: str) -> int:

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


Expand Down
3 changes: 2 additions & 1 deletion tests/integration_tests/model_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ def test_select_star(self):
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"""\
Expand Down

0 comments on commit 9412cf8

Please sign in to comment.