Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20231219-153446.yaml
Original file line number Diff line number Diff line change
@@ -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"
13 changes: 2 additions & 11 deletions dbt/adapters/bigquery/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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]]:
"""
Expand Down
8 changes: 8 additions & 0 deletions tests/functional/adapter/dbt_show/test_dbt_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
limit 5
"""

model_with_null_json_struct = """
select (struct<k json>(null)) as null_struct
"""


class TestBigQueryShowLimit(BaseShowLimit):
pass
Expand All @@ -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"])