You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2022/08/04 00:27:47 UTC

[superset] branch master updated: fix: BigQuery get_parameters_from_uri (#20966)

This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 7e501cd816 fix: BigQuery get_parameters_from_uri (#20966)
7e501cd816 is described below

commit 7e501cd816937608cddcd513bea9e7ea11bd3add
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Wed Aug 3 17:27:40 2022 -0700

    fix: BigQuery get_parameters_from_uri (#20966)
---
 superset/db_engine_specs/bigquery.py              |  4 +++-
 tests/unit_tests/db_engine_specs/test_bigquery.py | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/superset/db_engine_specs/bigquery.py b/superset/db_engine_specs/bigquery.py
index 51fd710ab3..85fb9576ac 100644
--- a/superset/db_engine_specs/bigquery.py
+++ b/superset/db_engine_specs/bigquery.py
@@ -386,7 +386,9 @@ class BigQueryEngineSpec(BaseEngineSpec):
 
         # Building parameters from encrypted_extra and uri
         if encrypted_extra:
-            return {**encrypted_extra, "query": value.query}
+            # ``value.query`` needs to be explicitly converted into a dict (from an
+            # ``immutabledict``) so that it can be JSON serialized
+            return {**encrypted_extra, "query": dict(value.query)}
 
         raise ValidationError("Invalid service credentials")
 
diff --git a/tests/unit_tests/db_engine_specs/test_bigquery.py b/tests/unit_tests/db_engine_specs/test_bigquery.py
index 292ea94a7b..db8ff14754 100644
--- a/tests/unit_tests/db_engine_specs/test_bigquery.py
+++ b/tests/unit_tests/db_engine_specs/test_bigquery.py
@@ -16,6 +16,8 @@
 # under the License.
 # pylint: disable=unused-argument, import-outside-toplevel, protected-access
 
+import json
+
 from pybigquery.sqlalchemy_bigquery import BigQueryDialect
 from pytest_mock import MockFixture
 from sqlalchemy import select
@@ -144,3 +146,17 @@ def test_select_star(mocker: MockFixture) -> None:
 FROM `my_table`
 LIMIT :param_1"""
     )
+
+
+def test_get_parameters_from_uri() -> None:
+    """
+    Test that the result from ``get_parameters_from_uri`` is JSON serializable.
+    """
+    from superset.db_engine_specs.bigquery import BigQueryEngineSpec
+
+    parameters = BigQueryEngineSpec.get_parameters_from_uri(
+        "bigquery://dbt-tutorial-347100/",
+        {"access_token": "TOP_SECRET"},
+    )
+    assert parameters == {"access_token": "TOP_SECRET", "query": {}}
+    assert json.loads(json.dumps(parameters)) == parameters