From 0788b5fdcc69ecafc7dfed0ffd760d05ceb7a34b Mon Sep 17 00:00:00 2001 From: Sebastian Liebscher <112352529+sebastianliebscher@users.noreply.github.com> Date: Thu, 11 May 2023 10:20:53 +0200 Subject: [PATCH] chore: fix deprecation warnings for SQLALchemy URL (#23770) --- superset/db_engine_specs/base.py | 2 +- superset/db_engine_specs/clickhouse.py | 2 +- superset/db_engine_specs/databricks.py | 2 +- superset/db_engine_specs/snowflake.py | 2 +- tests/unit_tests/db_engine_specs/test_drill.py | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/superset/db_engine_specs/base.py b/superset/db_engine_specs/base.py index a21c0b41006..98fb60c2756 100644 --- a/superset/db_engine_specs/base.py +++ b/superset/db_engine_specs/base.py @@ -1947,7 +1947,7 @@ class BasicParametersMixin: query.update(cls.encryption_parameters) return str( - URL( + URL.create( f"{cls.engine}+{cls.default_driver}".rstrip("+"), # type: ignore username=parameters.get("username"), password=parameters.get("password"), diff --git a/superset/db_engine_specs/clickhouse.py b/superset/db_engine_specs/clickhouse.py index 4c229ca1160..a62087bc6a6 100644 --- a/superset/db_engine_specs/clickhouse.py +++ b/superset/db_engine_specs/clickhouse.py @@ -314,7 +314,7 @@ class ClickHouseConnectEngineSpec(ClickHouseEngineSpec, BasicParametersMixin): if not url_params.get("database"): url_params["database"] = "__default__" url_params.pop("encryption", None) - return str(URL(f"{cls.engine}+{cls.default_driver}", **url_params)) + return str(URL.create(f"{cls.engine}+{cls.default_driver}", **url_params)) @classmethod def get_parameters_from_uri( diff --git a/superset/db_engine_specs/databricks.py b/superset/db_engine_specs/databricks.py index d9ad65e4906..f39e43aa60b 100644 --- a/superset/db_engine_specs/databricks.py +++ b/superset/db_engine_specs/databricks.py @@ -200,7 +200,7 @@ class DatabricksNativeEngineSpec(DatabricksODBCEngineSpec, BasicParametersMixin) query.update(cls.encryption_parameters) return str( - URL( + URL.create( f"{cls.engine}+{cls.default_driver}".rstrip("+"), username="token", password=parameters.get("access_token"), diff --git a/superset/db_engine_specs/snowflake.py b/superset/db_engine_specs/snowflake.py index 8b4c51ee8cd..c7049ae71d6 100644 --- a/superset/db_engine_specs/snowflake.py +++ b/superset/db_engine_specs/snowflake.py @@ -265,7 +265,7 @@ class SnowflakeEngineSpec(PostgresBaseEngineSpec): ] = None, ) -> str: return str( - URL( + URL.create( "snowflake", username=parameters.get("username"), password=parameters.get("password"), diff --git a/tests/unit_tests/db_engine_specs/test_drill.py b/tests/unit_tests/db_engine_specs/test_drill.py index 2930e0e81ea..c7463dcf1fa 100644 --- a/tests/unit_tests/db_engine_specs/test_drill.py +++ b/tests/unit_tests/db_engine_specs/test_drill.py @@ -36,7 +36,7 @@ def test_odbc_impersonation() -> None: from superset.db_engine_specs.drill import DrillEngineSpec - url = URL("drill+odbc") + url = URL.create("drill+odbc") username = "DoAsUser" url = DrillEngineSpec.get_url_for_impersonation(url, True, username) assert url.query["DelegationUID"] == username @@ -52,7 +52,7 @@ def test_jdbc_impersonation() -> None: from superset.db_engine_specs.drill import DrillEngineSpec - url = URL("drill+jdbc") + url = URL.create("drill+jdbc") username = "DoAsUser" url = DrillEngineSpec.get_url_for_impersonation(url, True, username) assert url.query["impersonation_target"] == username @@ -68,7 +68,7 @@ def test_sadrill_impersonation() -> None: from superset.db_engine_specs.drill import DrillEngineSpec - url = URL("drill+sadrill") + url = URL.create("drill+sadrill") username = "DoAsUser" url = DrillEngineSpec.get_url_for_impersonation(url, True, username) assert url.query["impersonation_target"] == username @@ -86,7 +86,7 @@ def test_invalid_impersonation() -> None: from superset.db_engine_specs.drill import DrillEngineSpec from superset.db_engine_specs.exceptions import SupersetDBAPIProgrammingError - url = URL("drill+foobar") + url = URL.create("drill+foobar") username = "DoAsUser" with pytest.raises(SupersetDBAPIProgrammingError):