Skip to content

Commit

Permalink
fix: BigQuery get_parameters_from_uri (apache#20966)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7e501cd)
  • Loading branch information
betodealmeida authored and jinghua-qa committed Aug 5, 2022
1 parent 5ca2ee4 commit 9585020
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion superset/db_engine_specs/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ def get_parameters_from_uri(

# 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")

Expand Down
16 changes: 16 additions & 0 deletions tests/unit_tests/db_engine_specs/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 9585020

Please sign in to comment.