fix: BigQuery get_parameters_from_uri (#20966)

This commit is contained in:
Beto Dealmeida 2022-08-03 17:27:40 -07:00 committed by GitHub
parent c33af83823
commit 7e501cd816
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

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

View File

@ -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