Skip to content

Commit 16938af

Browse files
Add refresh call in BigFramesHelper authz flow (#1336)
1 parent 0d5f221 commit 16938af

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: Fixes
2+
body: Ensure we have exchanged a refresh-token for a token prior to detemining notebook
3+
user in BigFrames
4+
time: 2025-09-15T09:53:08.063964-07:00
5+
custom:
6+
Author: colin-rogers-dbt
7+
Issue: "1219"

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,18 @@ def __init__(self, parsed_model: Dict, credentials: BigQueryCredentials) -> None
216216
model_timeout=parsed_model["config"].get("timeout") or _DEFAULT_BIGFRAMES_TIMEOUT
217217
)
218218

219+
def _get_token(self) -> str:
220+
"""Get a token from the credentials.
221+
If a token is not supplied by the user directly it is lazily created the first time we authenticates.
222+
BigFrames needs a token to determine the execution user but a call may not have
223+
"""
224+
creds = self._GoogleCredentials
225+
if creds.token:
226+
return creds.token
227+
else:
228+
creds.refresh()
229+
return creds.token
230+
219231
def _py_to_ipynb(self, compiled_code: str) -> str:
220232
notebook = nbformat.v4.new_notebook()
221233
# Put all codes in one cell.
@@ -332,7 +344,7 @@ def _config_notebook_job(
332344
response = request(
333345
method="GET",
334346
url="https://www.googleapis.com/oauth2/v2/userinfo",
335-
headers={"Authorization": f"Bearer {self._GoogleCredentials.token}"},
347+
headers={"Authorization": f"Bearer {self._get_token()}"},
336348
)
337349

338350
if response.status != 200:

0 commit comments

Comments
 (0)