Skip to content

Commit dd9ae46

Browse files
fix(bigquery): BigFrames notebook execution when using a service account with oauth (#1232)
Co-authored-by: Colin Rogers <[email protected]>
1 parent 3107abf commit dd9ae46

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Fixes
2+
body: BigFrames notebook execution when using a service account with oauth
3+
time: 2025-09-01T10:00:53.749318+02:00
4+
custom:
5+
Author: jspenmar
6+
Issue: "1231"

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
# Time interval in seconds between successive polling attempts to check the
4848
# notebook job's status in BigFrames mode.
4949
_COLAB_POLL_INTERVAL = 30
50+
# Suffix used by service accounts.
51+
_SERVICE_ACCOUNT_SUFFIX = "iam.gserviceaccount.com"
5052

5153

5254
class _BigQueryPythonHelper(PythonJobHelper):
@@ -332,12 +334,19 @@ def _config_notebook_job(
332334
url="https://www.googleapis.com/oauth2/v2/userinfo",
333335
headers={"Authorization": f"Bearer {self._GoogleCredentials.token}"},
334336
)
337+
335338
if response.status != 200:
336339
raise DbtRuntimeError(
337340
f"Failed to retrieve user info. Status: {response.status}, Body: {response.data}"
338341
)
339342
if user_email := json.loads(response.data).get("email"):
340-
notebook_execution_job.execution_user = user_email
343+
# In services such as Cloud Composer and Cloud Run, the authenticated user
344+
# is a service account with associated Application Default Credentials.
345+
# This does not require service account impersonation.
346+
if user_email and user_email.endswith(_SERVICE_ACCOUNT_SUFFIX):
347+
notebook_execution_job.service_account = user_email
348+
else:
349+
notebook_execution_job.execution_user = user_email
341350
else:
342351
raise DbtRuntimeError(
343352
"Authorization request to get user failed to return an email."

0 commit comments

Comments
 (0)