From 8a2b9ed5316d3a3deee2ee3ea2026dbb58d6e015 Mon Sep 17 00:00:00 2001 From: colin-rogers-dbt <111200756+colin-rogers-dbt@users.noreply.github.com> Date: Thu, 18 Jan 2024 12:11:40 -0800 Subject: [PATCH] 1.7.latest remove _json_from_json patch (#1074) * use dynamic schema in test_grant_access_to.py * use dynamic schema in test_grant_access_to.py * revert setup * remove _json_from_json patch --- .changes/unreleased/Fixes-20231219-153446.yaml | 6 ++++++ dbt/adapters/bigquery/connections.py | 12 +----------- tests/functional/adapter/dbt_show/test_dbt_show.py | 8 ++++++++ 3 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 .changes/unreleased/Fixes-20231219-153446.yaml diff --git a/.changes/unreleased/Fixes-20231219-153446.yaml b/.changes/unreleased/Fixes-20231219-153446.yaml new file mode 100644 index 000000000..44a858eb8 --- /dev/null +++ b/.changes/unreleased/Fixes-20231219-153446.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: remove json patch to leverage bigquery-python improvement +time: 2023-12-19T15:34:46.843931-08:00 +custom: + Author: colin-rogers-dbt + Issue: "1055" diff --git a/dbt/adapters/bigquery/connections.py b/dbt/adapters/bigquery/connections.py index de84e4bf8..132854748 100644 --- a/dbt/adapters/bigquery/connections.py +++ b/dbt/adapters/bigquery/connections.py @@ -15,7 +15,7 @@ import google.auth import google.auth.exceptions -import google.cloud.bigquery as bigquery +import google.cloud.bigquery import google.cloud.exceptions from google.api_core import retry, client_info from google.auth import impersonated_credentials @@ -63,16 +63,6 @@ ) -# Override broken json deserializer for dbt show --inline -# can remove once this is fixed: https://github.com/googleapis/python-bigquery/issues/1500 -def _json_from_json(value, _): - """NOOP string -> string coercion""" - return json.loads(value) - - -bigquery._helpers._CELLDATA_FROM_JSON["JSON"] = _json_from_json - - @lru_cache() def get_bigquery_defaults(scopes=None) -> Tuple[Any, Optional[str]]: """ diff --git a/tests/functional/adapter/dbt_show/test_dbt_show.py b/tests/functional/adapter/dbt_show/test_dbt_show.py index 203d7031b..acb54cc47 100644 --- a/tests/functional/adapter/dbt_show/test_dbt_show.py +++ b/tests/functional/adapter/dbt_show/test_dbt_show.py @@ -24,6 +24,10 @@ limit 5 """ +model_with_null_json_struct = """ + select (struct(null)) as null_struct +""" + class TestBigQueryShowLimit(BaseShowLimit): pass @@ -40,7 +44,11 @@ class TestBigQueryShowSqlWorksWithJSONStruct: def models(self): return { "json_struct_model.sql": model_with_json_struct, + "null_json_struct_model.sql": model_with_null_json_struct, } def test_sql_header(self, project): run_dbt(["show", "--select", "json_struct_model"]) + + def test_show_with_null_json_struct(self, project): + run_dbt(["show", "--select", "null_json_struct_model"])