Skip to content

Commit f4cf486

Browse files
authored
fix(source/bigquery): allowed datasets project id issue with client oauth (googleapis#1663)
## Description --- allowed datasets default project id is from client, which may not be available if useClientOAuth=True, changed to use r.Project instead. ## PR Checklist --- > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [ ] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #<issue_number_goes_here>
1 parent 94eba1f commit f4cf486

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

internal/sources/bigquery/bigquery.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,20 @@ func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.So
127127
datasetID = parts[1]
128128
allowedFullID = allowed
129129
} else {
130-
projectID = client.Project()
130+
projectID = r.Project
131131
datasetID = allowed
132132
allowedFullID = fmt.Sprintf("%s.%s", projectID, datasetID)
133133
}
134134

135-
dataset := client.DatasetInProject(projectID, datasetID)
136-
_, err := dataset.Metadata(ctx)
137-
if err != nil {
138-
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == http.StatusNotFound {
139-
return nil, fmt.Errorf("allowedDataset '%s' not found in project '%s'", datasetID, projectID)
135+
if client != nil {
136+
dataset := client.DatasetInProject(projectID, datasetID)
137+
_, err := dataset.Metadata(ctx)
138+
if err != nil {
139+
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == http.StatusNotFound {
140+
return nil, fmt.Errorf("allowedDataset '%s' not found in project '%s'", datasetID, projectID)
141+
}
142+
return nil, fmt.Errorf("failed to verify allowedDataset '%s' in project '%s': %w", datasetID, projectID, err)
140143
}
141-
return nil, fmt.Errorf("failed to verify allowedDataset '%s' in project '%s': %w", datasetID, projectID, err)
142144
}
143145
allowedDatasets[allowedFullID] = struct{}{}
144146
}

0 commit comments

Comments
 (0)