Skip to content

Commit eb33650

Browse files
Added Support for api_endpoint config (#1045)
Co-authored-by: Colin Rogers <[email protected]> Co-authored-by: Colin <[email protected]>
1 parent f998718 commit eb33650

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Features
2+
body: Make Bigquery `api_endpoint` config option available for dbt client
3+
time: 2025-05-01T08:18:44.483014492Z
4+
custom:
5+
Author: OTooleMichael
6+
Issue: https://github.com/dbt-labs/dbt-bigquery/pull/1017

dbt-bigquery/src/dbt/adapters/bigquery/clients.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ def _create_bigquery_client(credentials: BigQueryCredentials) -> BigQueryClient:
6161
create_google_credentials(credentials),
6262
location=getattr(credentials, "location", None),
6363
client_info=ClientInfo(user_agent=f"dbt-bigquery-{dbt_version.version}"),
64-
client_options=ClientOptions(quota_project_id=credentials.quota_project),
64+
client_options=ClientOptions(
65+
quota_project_id=credentials.quota_project, api_endpoint=credentials.api_endpoint
66+
),
6567
)
6668

6769

dbt-bigquery/src/dbt/adapters/bigquery/credentials.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class BigQueryCredentials(Credentials):
5555
execution_project: Optional[str] = None
5656
quota_project: Optional[str] = None
5757
location: Optional[str] = None
58+
api_endpoint: Optional[str] = None
5859
priority: Optional[Priority] = None
5960
maximum_bytes_billed: Optional[int] = None
6061
impersonate_service_account: Optional[str] = None

dbt-bigquery/tests/unit/test_bigquery_adapter.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ def setUp(self):
8484
"priority": "batch",
8585
"maximum_bytes_billed": 0,
8686
},
87+
"api_endpoint": {
88+
"type": "bigquery",
89+
"method": "oauth",
90+
"project": "dbt-unit-000000",
91+
"schema": "dummy_schema",
92+
"threads": 1,
93+
"api_endpoint": "https://localhost:3001",
94+
},
8795
"impersonate": {
8896
"type": "bigquery",
8997
"method": "oauth",
@@ -419,7 +427,7 @@ def test_cancel_open_connections_single(self):
419427
self.assertEqual(len(list(adapter.cancel_open_connections())), 1)
420428

421429
@patch("dbt.adapters.bigquery.clients.ClientOptions")
422-
@patch("dbt.adapters.bigquery.credentials.default")
430+
@patch("dbt.adapters.bigquery.credentials._create_bigquery_defaults")
423431
@patch("dbt.adapters.bigquery.clients.BigQueryClient")
424432
def test_location_user_agent(self, MockClient, mock_auth_default, MockClientOptions):
425433
creds = MagicMock()
@@ -439,6 +447,28 @@ def test_location_user_agent(self, MockClient, mock_auth_default, MockClientOpti
439447
client_options=mock_client_options,
440448
)
441449

450+
@patch("dbt.adapters.bigquery.clients.ClientOptions")
451+
@patch("dbt.adapters.bigquery.credentials._create_bigquery_defaults")
452+
@patch("dbt.adapters.bigquery.clients.BigQueryClient")
453+
def test_api_endpoint_settable(self, MockClient, mock_auth_default, MockClientOptions):
454+
"""Ensure api_endpoint is set on ClientOptions and passed to BigQueryClient."""
455+
456+
creds = MagicMock()
457+
mock_auth_default.return_value = (creds, MagicMock())
458+
mock_client_options = MockClientOptions.return_value
459+
460+
adapter = self.get_adapter("api_endpoint")
461+
connection = adapter.acquire_connection("dummy")
462+
MockClient.assert_not_called()
463+
connection.handle
464+
465+
MockClientOptions.assert_called_once()
466+
kwargs = MockClientOptions.call_args.kwargs
467+
assert kwargs.get("api_endpoint") == "https://localhost:3001"
468+
469+
MockClient.assert_called_once()
470+
assert MockClient.call_args.kwargs["client_options"] is mock_client_options
471+
442472

443473
class HasUserAgent:
444474
PAT = re.compile(r"dbt-bigquery-\d+\.\d+\.\d+((a|b|rc)\d+)?")

0 commit comments

Comments
 (0)