Skip to content

Commit

Permalink
fix: search_path in RDS
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Jul 19, 2023
1 parent 9c6d535 commit 6322ced
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
13 changes: 13 additions & 0 deletions superset/db_engine_specs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,19 @@ def adjust_engine_params( # pylint: disable=unused-argument
**cls.enforce_uri_query_params.get(uri.get_driver_name(), {}),
}

@classmethod
def get_prequeries(
cls,
catalog: str | None = None,
schema: str | None = None,
) -> [str]:
"""
Return pre-session queries.
This are useful for setting the default catalog and/or schema.
"""
return []

@classmethod
def patch(cls) -> None:
"""
Expand Down
21 changes: 5 additions & 16 deletions superset/db_engine_specs/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,12 @@ def get_schema_from_engine_params(
return None

@classmethod
def adjust_engine_params(
def get_prequeries(
cls,
uri: URL,
connect_args: dict[str, Any],
catalog: Optional[str] = None,
schema: Optional[str] = None,
) -> tuple[URL, dict[str, Any]]:
if not schema:
return uri, connect_args

options = parse_options(connect_args)
options["search_path"] = schema
connect_args["options"] = " ".join(
f"-c{key}={value}" for key, value in options.items()
)

return uri, connect_args
catalog: str | None = None,
schema: str | None = None,
) -> [str]:
return [f'set search_path = "{schema}"']

@classmethod
def get_allow_cost_estimate(cls, extra: dict[str, Any]) -> bool:
Expand Down
2 changes: 2 additions & 0 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ def get_raw_connection(
schema=schema, nullpool=nullpool, source=source
) as engine:
with closing(engine.raw_connection()) as conn:
for prequery in self.db_engine_spec.get_prequeries(schema=schema):
conn.execute(prequery)
yield conn

def get_default_schema_for_query(self, query: "Query") -> Optional[str]:
Expand Down

0 comments on commit 6322ced

Please sign in to comment.