Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Make Bigquery `api_endpoint` config option available for dbt client
time: 2025-05-01T08:18:44.483014492Z
custom:
Author: OTooleMichael
Issue: https://github.com/dbt-labs/dbt-bigquery/pull/1017
6 changes: 5 additions & 1 deletion dbt-bigquery/src/dbt/adapters/bigquery/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ def create_dataproc_batch_controller_client(

@BQ_DEFAULT_RETRY
def _create_bigquery_client(credentials: BigQueryCredentials) -> BigQueryClient:
kwargs_options = {}
if credentials.api_endpoint:
kwargs_options["api_endpoint"] = credentials.api_endpoint

return BigQueryClient(
credentials.execution_project,
create_google_credentials(credentials),
location=getattr(credentials, "location", None),
client_info=ClientInfo(user_agent=f"dbt-bigquery-{dbt_version.version}"),
client_options=ClientOptions(quota_project_id=credentials.quota_project),
client_options=ClientOptions(quota_project_id=credentials.quota_project, **kwargs_options),
)


Expand Down
1 change: 1 addition & 0 deletions dbt-bigquery/src/dbt/adapters/bigquery/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class BigQueryCredentials(Credentials):
execution_project: Optional[str] = None
quota_project: Optional[str] = None
location: Optional[str] = None
api_endpoint: Optional[str] = None
priority: Optional[Priority] = None
maximum_bytes_billed: Optional[int] = None
impersonate_service_account: Optional[str] = None
Expand Down
32 changes: 31 additions & 1 deletion dbt-bigquery/tests/unit/test_bigquery_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ def setUp(self):
"priority": "batch",
"maximum_bytes_billed": 0,
},
"api_endpoint": {
"type": "bigquery",
"method": "oauth",
"project": "dbt-unit-000000",
"schema": "dummy_schema",
"threads": 1,
"api_endpoint": "https://localhost:3001",
},
"impersonate": {
"type": "bigquery",
"method": "oauth",
Expand Down Expand Up @@ -419,7 +427,7 @@ def test_cancel_open_connections_single(self):
self.assertEqual(len(list(adapter.cancel_open_connections())), 1)

@patch("dbt.adapters.bigquery.clients.ClientOptions")
@patch("dbt.adapters.bigquery.credentials.default")
@patch("dbt.adapters.bigquery.credentials._create_bigquery_defaults")
@patch("dbt.adapters.bigquery.clients.BigQueryClient")
def test_location_user_agent(self, MockClient, mock_auth_default, MockClientOptions):
creds = MagicMock()
Expand All @@ -439,6 +447,28 @@ def test_location_user_agent(self, MockClient, mock_auth_default, MockClientOpti
client_options=mock_client_options,
)

@patch("dbt.adapters.bigquery.clients.ClientOptions")
@patch("dbt.adapters.bigquery.credentials._create_bigquery_defaults")
@patch("dbt.adapters.bigquery.clients.BigQueryClient")
def test_api_endpoint_settable(self, MockClient, mock_auth_default, MockClientOptions):
"""Ensure api_endpoint is set on ClientOptions and passed to BigQueryClient."""

creds = MagicMock()
mock_auth_default.return_value = (creds, MagicMock())
mock_client_options = MockClientOptions.return_value

adapter = get_adapter("api_endpoint")
adapter.acquire_connection("dummy")
MockClient.assert_not_called()
connection.handle

MockClientOptions.assert_called_once()
kwargs = MockClientOptions.call_args.kwargs
assert kwargs.get("api_endpoint") == "https://localhost:3001"

MockClient.assert_called_once()
assert MockClient.call_args.kwargs["client_options"] is mock_client_options


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