Skip to content

Commit 12bc4c0

Browse files
dlstadthercpcloud
authored andcommitted
fix(bigquery): maintain custom client project id when provided
1 parent 5fc1a8b commit 12bc4c0

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

ibis/backends/bigquery/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ def do_connect(
410410
An instance of the BigQuery backend.
411411
412412
"""
413-
default_project_id = client.project if client is not None else project_id
413+
client_project_id = client.project if client is not None else None
414+
default_project_id = None
414415

415416
# Only need `credentials` to create a `client` and
416417
# `storage_client`, so only one or the other needs to be set.
@@ -443,7 +444,7 @@ def do_connect(
443444
use_local_webserver=auth_local_webserver,
444445
)
445446

446-
project_id = project_id or default_project_id
447+
project_id = client_project_id or project_id or default_project_id
447448

448449
(
449450
self.data_project,

ibis/backends/bigquery/tests/system/test_connect.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,21 @@ def test_create_table_from_memtable_needs_quotes(project_id, dataset_id, credent
256256
assert t.schema() == ibis.schema(schema)
257257
finally:
258258
con.drop_table(name)
259+
260+
261+
def test_project_id_from_arg(project_id):
262+
con = ibis.bigquery.connect(project_id=project_id)
263+
assert con.project_id == project_id
264+
265+
266+
def test_project_id_from_client(project_id):
267+
bq_client = bq.Client(project=project_id)
268+
con = ibis.bigquery.connect(client=bq_client, project_id="not-a-real-project")
269+
assert con.project_id == project_id
270+
271+
272+
def test_project_id_from_default(default_credentials):
273+
_, default_project_id = default_credentials
274+
# `connect()` re-evaluates default credentials and sets project_id since no client nor explicit project_id is provided
275+
con = ibis.bigquery.connect()
276+
assert con.project_id == default_project_id

0 commit comments

Comments
 (0)