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 f9bb791d2..0f2f70f74 100644 --- a/dbt/adapters/bigquery/connections.py +++ b/dbt/adapters/bigquery/connections.py @@ -17,7 +17,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 @@ -33,6 +33,7 @@ DbtRuntimeError, DbtConfigError, ) + from dbt_common.exceptions import DbtDatabaseError from dbt.adapters.exceptions.connection import FailedToConnectError from dbt.adapters.base import BaseConnectionManager @@ -63,16 +64,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"])