You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2023/07/06 23:12:45 UTC

[airflow] branch main updated: Fix BigQuery transfer operators to respect project_id arguments (#32232)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 2d690de110 Fix BigQuery transfer operators to respect project_id arguments (#32232)
2d690de110 is described below

commit 2d690de110825ba09b9445967b47c44edd8f151c
Author: Avinash Holla Pandeshwar <av...@gmail.com>
AuthorDate: Fri Jul 7 04:42:37 2023 +0530

    Fix BigQuery transfer operators to respect project_id arguments (#32232)
---
 .../google/cloud/transfers/bigquery_to_gcs.py      |  6 +-
 .../google/cloud/transfers/gcs_to_bigquery.py      | 31 ++++----
 .../google/cloud/transfers/test_bigquery_to_gcs.py | 12 +--
 .../google/cloud/transfers/test_gcs_to_bigquery.py | 92 +++++++++++++++-------
 4 files changed, 86 insertions(+), 55 deletions(-)

diff --git a/airflow/providers/google/cloud/transfers/bigquery_to_gcs.py b/airflow/providers/google/cloud/transfers/bigquery_to_gcs.py
index 8836e3ee35..4677511151 100644
--- a/airflow/providers/google/cloud/transfers/bigquery_to_gcs.py
+++ b/airflow/providers/google/cloud/transfers/bigquery_to_gcs.py
@@ -146,7 +146,7 @@ class BigQueryToGCSOperator(BaseOperator):
     def _prepare_configuration(self):
         source_project, source_dataset, source_table = self.hook.split_tablename(
             table_input=self.source_project_dataset_table,
-            default_project_id=self.project_id or self.hook.project_id,
+            default_project_id=self.hook.project_id,
             var_name="source_project_dataset_table",
         )
 
@@ -184,7 +184,7 @@ class BigQueryToGCSOperator(BaseOperator):
 
         return hook.insert_job(
             configuration=configuration,
-            project_id=configuration["extract"]["sourceTable"]["projectId"],
+            project_id=self.project_id or hook.project_id,
             location=self.location,
             job_id=job_id,
             timeout=self.result_timeout,
@@ -255,7 +255,7 @@ class BigQueryToGCSOperator(BaseOperator):
                 trigger=BigQueryInsertJobTrigger(
                     conn_id=self.gcp_conn_id,
                     job_id=job_id,
-                    project_id=self.hook.project_id,
+                    project_id=self.project_id or self.hook.project_id,
                 ),
                 method_name="execute_complete",
             )
diff --git a/airflow/providers/google/cloud/transfers/gcs_to_bigquery.py b/airflow/providers/google/cloud/transfers/gcs_to_bigquery.py
index da462eae74..46c5adc95b 100644
--- a/airflow/providers/google/cloud/transfers/gcs_to_bigquery.py
+++ b/airflow/providers/google/cloud/transfers/gcs_to_bigquery.py
@@ -301,7 +301,7 @@ class GCSToBigQueryOperator(BaseOperator):
         # Submit a new job without waiting for it to complete.
         return hook.insert_job(
             configuration=self.configuration,
-            project_id=self.project_id,
+            project_id=self.project_id or hook.project_id,
             location=self.location,
             job_id=job_id,
             timeout=self.result_timeout,
@@ -359,7 +359,7 @@ class GCSToBigQueryOperator(BaseOperator):
 
         if self.external_table:
             self.log.info("Creating a new BigQuery table for storing data...")
-            table_obj_api_repr = self._create_empty_table()
+            table_obj_api_repr = self._create_external_table()
 
             BigQueryTableLink.persist(
                 context=context,
@@ -381,7 +381,7 @@ class GCSToBigQueryOperator(BaseOperator):
             except Conflict:
                 # If the job already exists retrieve it
                 job = self.hook.get_job(
-                    project_id=self.hook.project_id,
+                    project_id=self.project_id or self.hook.project_id,
                     location=self.location,
                     job_id=job_id,
                 )
@@ -414,12 +414,12 @@ class GCSToBigQueryOperator(BaseOperator):
                                 persist_kwargs = {
                                     "context": context,
                                     "task_instance": self,
-                                    "project_id": self.hook.project_id,
                                     "table_id": table,
                                 }
                                 if not isinstance(table, str):
                                     persist_kwargs["table_id"] = table["tableId"]
                                     persist_kwargs["dataset_id"] = table["datasetId"]
+                                    persist_kwargs["project_id"] = table["projectId"]
                                 BigQueryTableLink.persist(**persist_kwargs)
 
             self.job_id = job.job_id
@@ -430,7 +430,7 @@ class GCSToBigQueryOperator(BaseOperator):
                     trigger=BigQueryInsertJobTrigger(
                         conn_id=self.gcp_conn_id,
                         job_id=self.job_id,
-                        project_id=self.hook.project_id,
+                        project_id=self.project_id or self.hook.project_id,
                     ),
                     method_name="execute_complete",
                 )
@@ -475,7 +475,9 @@ class GCSToBigQueryOperator(BaseOperator):
                 }
             }
             try:
-                job_id = hook.insert_job(configuration=self.configuration, project_id=hook.project_id)
+                job_id = hook.insert_job(
+                    configuration=self.configuration, project_id=self.project_id or hook.project_id
+                )
                 rows = list(hook.get_job(job_id=job_id, location=self.location).result())
             except BadRequest as e:
                 if "Unrecognized name:" in e.message:
@@ -498,12 +500,7 @@ class GCSToBigQueryOperator(BaseOperator):
             else:
                 raise RuntimeError(f"The {select_command} returned no rows!")
 
-    def _create_empty_table(self):
-        self.project_id, dataset_id, table_id = self.hook.split_tablename(
-            table_input=self.destination_project_dataset_table,
-            default_project_id=self.project_id or self.hook.project_id,
-        )
-
+    def _create_external_table(self):
         external_config_api_repr = {
             "autodetect": self.autodetect,
             "sourceFormat": self.source_format,
@@ -549,7 +546,7 @@ class GCSToBigQueryOperator(BaseOperator):
 
         # build table definition
         table = Table(
-            table_ref=TableReference.from_string(self.destination_project_dataset_table, self.project_id)
+            table_ref=TableReference.from_string(self.destination_project_dataset_table, self.hook.project_id)
         )
         table.external_data_configuration = external_config
         if self.labels:
@@ -567,7 +564,7 @@ class GCSToBigQueryOperator(BaseOperator):
         self.log.info("Creating external table: %s", self.destination_project_dataset_table)
         self.hook.create_empty_table(
             table_resource=table_obj_api_repr,
-            project_id=self.project_id,
+            project_id=self.project_id or self.hook.project_id,
             location=self.location,
             exists_ok=True,
         )
@@ -575,9 +572,9 @@ class GCSToBigQueryOperator(BaseOperator):
         return table_obj_api_repr
 
     def _use_existing_table(self):
-        self.project_id, destination_dataset, destination_table = self.hook.split_tablename(
+        destination_project_id, destination_dataset, destination_table = self.hook.split_tablename(
             table_input=self.destination_project_dataset_table,
-            default_project_id=self.project_id or self.hook.project_id,
+            default_project_id=self.hook.project_id,
             var_name="destination_project_dataset_table",
         )
 
@@ -597,7 +594,7 @@ class GCSToBigQueryOperator(BaseOperator):
                 "autodetect": self.autodetect,
                 "createDisposition": self.create_disposition,
                 "destinationTable": {
-                    "projectId": self.project_id,
+                    "projectId": destination_project_id,
                     "datasetId": destination_dataset,
                     "tableId": destination_table,
                 },
diff --git a/tests/providers/google/cloud/transfers/test_bigquery_to_gcs.py b/tests/providers/google/cloud/transfers/test_bigquery_to_gcs.py
index b1d0563f58..b7bf8bef62 100644
--- a/tests/providers/google/cloud/transfers/test_bigquery_to_gcs.py
+++ b/tests/providers/google/cloud/transfers/test_bigquery_to_gcs.py
@@ -31,6 +31,7 @@ TASK_ID = "test-bq-create-table-operator"
 TEST_DATASET = "test-dataset"
 TEST_TABLE_ID = "test-table-id"
 PROJECT_ID = "test-project-id"
+JOB_PROJECT_ID = "job-project-id"
 
 
 class TestBigQueryToGCSOperator:
@@ -66,7 +67,7 @@ class TestBigQueryToGCSOperator:
         mock_hook.return_value.split_tablename.return_value = (PROJECT_ID, TEST_DATASET, TEST_TABLE_ID)
         mock_hook.return_value.generate_job_id.return_value = real_job_id
         mock_hook.return_value.insert_job.return_value = MagicMock(job_id="real_job_id", error_result=False)
-        mock_hook.return_value.project_id = PROJECT_ID
+        mock_hook.return_value.project_id = JOB_PROJECT_ID
 
         operator = BigQueryToGCSOperator(
             task_id=TASK_ID,
@@ -77,13 +78,14 @@ class TestBigQueryToGCSOperator:
             field_delimiter=field_delimiter,
             print_header=print_header,
             labels=labels,
+            project_id=JOB_PROJECT_ID,
         )
         operator.execute(context=mock.MagicMock())
 
         mock_hook.return_value.insert_job.assert_called_once_with(
             job_id="123456_hash",
             configuration=expected_configuration,
-            project_id=PROJECT_ID,
+            project_id=JOB_PROJECT_ID,
             location=None,
             timeout=None,
             retry=DEFAULT_RETRY,
@@ -122,10 +124,10 @@ class TestBigQueryToGCSOperator:
         mock_hook.return_value.split_tablename.return_value = (PROJECT_ID, TEST_DATASET, TEST_TABLE_ID)
         mock_hook.return_value.generate_job_id.return_value = real_job_id
         mock_hook.return_value.insert_job.return_value = MagicMock(job_id="real_job_id", error_result=False)
-        mock_hook.return_value.project_id = PROJECT_ID
+        mock_hook.return_value.project_id = JOB_PROJECT_ID
 
         operator = BigQueryToGCSOperator(
-            project_id=PROJECT_ID,
+            project_id=JOB_PROJECT_ID,
             task_id=TASK_ID,
             source_project_dataset_table=source_project_dataset_table,
             destination_cloud_storage_uris=destination_cloud_storage_uris,
@@ -146,7 +148,7 @@ class TestBigQueryToGCSOperator:
         mock_hook.return_value.insert_job.assert_called_once_with(
             configuration=expected_configuration,
             job_id="123456_hash",
-            project_id=PROJECT_ID,
+            project_id=JOB_PROJECT_ID,
             location=None,
             timeout=None,
             retry=DEFAULT_RETRY,
diff --git a/tests/providers/google/cloud/transfers/test_gcs_to_bigquery.py b/tests/providers/google/cloud/transfers/test_gcs_to_bigquery.py
index 80958f281f..1a0f381837 100644
--- a/tests/providers/google/cloud/transfers/test_gcs_to_bigquery.py
+++ b/tests/providers/google/cloud/transfers/test_gcs_to_bigquery.py
@@ -40,6 +40,7 @@ TEST_BUCKET = "test-bucket"
 PROJECT_ID = "test-project"
 DATASET = "dataset"
 TABLE = "table"
+JOB_PROJECT_ID = "job-project-id"
 WRITE_DISPOSITION = "WRITE_TRUNCATE"
 MAX_ID_KEY = "id"
 TEST_DATASET_LOCATION = "US"
@@ -85,6 +86,7 @@ class TestGCSToBigQueryOperator:
             schema_fields=SCHEMA_FIELDS,
             max_id_key=MAX_ID_KEY,
             external_table=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         result = operator.execute(context=MagicMock())
@@ -93,7 +95,7 @@ class TestGCSToBigQueryOperator:
         hook.return_value.create_empty_table.assert_called_once_with(
             exists_ok=True,
             location=None,
-            project_id=PROJECT_ID,
+            project_id=JOB_PROJECT_ID,
             table_resource={
                 "tableReference": {"projectId": PROJECT_ID, "datasetId": DATASET, "tableId": TABLE},
                 "labels": {},
@@ -123,7 +125,7 @@ class TestGCSToBigQueryOperator:
                     "schemaUpdateOptions": [],
                 }
             },
-            project_id=hook.return_value.project_id,
+            project_id=JOB_PROJECT_ID,
         )
 
     @mock.patch(GCS_TO_BQ_PATH.format("BigQueryHook"))
@@ -145,6 +147,7 @@ class TestGCSToBigQueryOperator:
             max_id_key=MAX_ID_KEY,
             write_disposition=WRITE_DISPOSITION,
             external_table=False,
+            project_id=JOB_PROJECT_ID,
         )
 
         result = operator.execute(context=MagicMock())
@@ -172,7 +175,7 @@ class TestGCSToBigQueryOperator:
                 job_id=pytest.real_job_id,
                 location=None,
                 nowait=True,
-                project_id=hook.return_value.split_tablename.return_value[0],
+                project_id=JOB_PROJECT_ID,
                 retry=DEFAULT_RETRY,
                 timeout=None,
             ),
@@ -184,7 +187,7 @@ class TestGCSToBigQueryOperator:
                         "schemaUpdateOptions": [],
                     }
                 },
-                project_id=hook.return_value.project_id,
+                project_id=JOB_PROJECT_ID,
             ),
         ]
 
@@ -208,6 +211,7 @@ class TestGCSToBigQueryOperator:
                 max_id_key=MAX_ID_KEY,
                 write_disposition=WRITE_DISPOSITION,
                 external_table=False,
+                project_id=JOB_PROJECT_ID,
             )
             operator.execute(context=MagicMock())
 
@@ -233,7 +237,7 @@ class TestGCSToBigQueryOperator:
                 job_id=pytest.real_job_id,
                 location=None,
                 nowait=True,
-                project_id=hook.return_value.split_tablename.return_value[0],
+                project_id=JOB_PROJECT_ID,
                 retry=DEFAULT_RETRY,
                 timeout=None,
             ),
@@ -245,7 +249,7 @@ class TestGCSToBigQueryOperator:
                         "schemaUpdateOptions": [],
                     }
                 },
-                project_id=hook.return_value.project_id,
+                project_id=JOB_PROJECT_ID,
             ),
         ]
 
@@ -269,13 +273,14 @@ class TestGCSToBigQueryOperator:
             write_disposition=WRITE_DISPOSITION,
             external_table=True,
             labels=LABELS,
+            project_id=JOB_PROJECT_ID,
         )
 
         operator.execute(context=MagicMock())
         hook.return_value.create_empty_table.assert_called_once_with(
             exists_ok=True,
             location=None,
-            project_id=PROJECT_ID,
+            project_id=JOB_PROJECT_ID,
             table_resource={
                 "tableReference": {"projectId": PROJECT_ID, "datasetId": DATASET, "tableId": TABLE},
                 "labels": LABELS,
@@ -316,6 +321,7 @@ class TestGCSToBigQueryOperator:
             schema_fields=SCHEMA_FIELDS,
             external_table=False,
             labels=LABELS,
+            project_id=JOB_PROJECT_ID,
         )
 
         operator.execute(context=MagicMock())
@@ -342,7 +348,7 @@ class TestGCSToBigQueryOperator:
                 job_id=pytest.real_job_id,
                 location=None,
                 nowait=True,
-                project_id=hook.return_value.split_tablename.return_value[0],
+                project_id=JOB_PROJECT_ID,
                 retry=DEFAULT_RETRY,
                 timeout=None,
             )
@@ -368,13 +374,14 @@ class TestGCSToBigQueryOperator:
             schema_fields=SCHEMA_FIELDS,
             description=DESCRIPTION,
             external_table=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         operator.execute(context=MagicMock())
         hook.return_value.create_empty_table.assert_called_once_with(
             exists_ok=True,
             location=None,
-            project_id=PROJECT_ID,
+            project_id=JOB_PROJECT_ID,
             table_resource={
                 "tableReference": {"projectId": PROJECT_ID, "datasetId": DATASET, "tableId": TABLE},
                 "labels": {},
@@ -416,6 +423,7 @@ class TestGCSToBigQueryOperator:
             write_disposition=WRITE_DISPOSITION,
             external_table=False,
             description=DESCRIPTION,
+            project_id=JOB_PROJECT_ID,
         )
 
         operator.execute(context=MagicMock())
@@ -441,7 +449,7 @@ class TestGCSToBigQueryOperator:
                         fieldDelimiter=",",
                     ),
                 },
-                project_id=hook.return_value.split_tablename.return_value[0],
+                project_id=JOB_PROJECT_ID,
                 location=None,
                 job_id=pytest.real_job_id,
                 timeout=None,
@@ -467,6 +475,7 @@ class TestGCSToBigQueryOperator:
             write_disposition=WRITE_DISPOSITION,
             destination_project_dataset_table=TEST_EXPLICIT_DEST,
             external_table=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         operator.execute(context=MagicMock())
@@ -474,7 +483,7 @@ class TestGCSToBigQueryOperator:
         hook.return_value.create_empty_table.assert_called_once_with(
             exists_ok=True,
             location=None,
-            project_id=PROJECT_ID,
+            project_id=JOB_PROJECT_ID,
             table_resource={
                 "tableReference": {"projectId": PROJECT_ID, "datasetId": DATASET, "tableId": TABLE},
                 "labels": {},
@@ -515,6 +524,7 @@ class TestGCSToBigQueryOperator:
             write_disposition=WRITE_DISPOSITION,
             destination_project_dataset_table=TEST_EXPLICIT_DEST,
             external_table=False,
+            project_id=JOB_PROJECT_ID,
         )
 
         operator.execute(context=MagicMock())
@@ -545,7 +555,7 @@ class TestGCSToBigQueryOperator:
                 job_id=pytest.real_job_id,
                 location=None,
                 nowait=True,
-                project_id=hook.return_value.split_tablename.return_value[0],
+                project_id=JOB_PROJECT_ID,
                 retry=DEFAULT_RETRY,
                 timeout=None,
             )
@@ -569,6 +579,7 @@ class TestGCSToBigQueryOperator:
             write_disposition=WRITE_DISPOSITION,
             destination_project_dataset_table=TEST_EXPLICIT_DEST,
             external_table=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         operator.execute(context=MagicMock())
@@ -576,7 +587,7 @@ class TestGCSToBigQueryOperator:
         hook.return_value.create_empty_table.assert_called_once_with(
             exists_ok=True,
             location=None,
-            project_id=PROJECT_ID,
+            project_id=JOB_PROJECT_ID,
             table_resource={
                 "tableReference": {"projectId": PROJECT_ID, "datasetId": DATASET, "tableId": TABLE},
                 "labels": {},
@@ -615,6 +626,7 @@ class TestGCSToBigQueryOperator:
             destination_project_dataset_table=TEST_EXPLICIT_DEST,
             write_disposition=WRITE_DISPOSITION,
             external_table=False,
+            project_id=JOB_PROJECT_ID,
         )
 
         operator.execute(context=MagicMock())
@@ -645,7 +657,7 @@ class TestGCSToBigQueryOperator:
                 job_id=pytest.real_job_id,
                 location=None,
                 nowait=True,
-                project_id=hook.return_value.split_tablename.return_value[0],
+                project_id=JOB_PROJECT_ID,
                 retry=DEFAULT_RETRY,
                 timeout=None,
             )
@@ -672,6 +684,7 @@ class TestGCSToBigQueryOperator:
             write_disposition=WRITE_DISPOSITION,
             destination_project_dataset_table=TEST_EXPLICIT_DEST,
             external_table=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         operator.execute(context=MagicMock())
@@ -679,7 +692,7 @@ class TestGCSToBigQueryOperator:
         bq_hook.return_value.create_empty_table.assert_called_once_with(
             exists_ok=True,
             location=None,
-            project_id=PROJECT_ID,
+            project_id=JOB_PROJECT_ID,
             table_resource={
                 "tableReference": {"projectId": PROJECT_ID, "datasetId": DATASET, "tableId": TABLE},
                 "labels": {},
@@ -723,6 +736,7 @@ class TestGCSToBigQueryOperator:
             destination_project_dataset_table=TEST_EXPLICIT_DEST,
             write_disposition=WRITE_DISPOSITION,
             external_table=False,
+            project_id=JOB_PROJECT_ID,
         )
 
         operator.execute(context=MagicMock())
@@ -746,7 +760,7 @@ class TestGCSToBigQueryOperator:
                         "encoding": "UTF-8",
                     }
                 },
-                project_id=bq_hook.return_value.split_tablename.return_value[0],
+                project_id=JOB_PROJECT_ID,
                 location=None,
                 job_id=pytest.real_job_id,
                 timeout=None,
@@ -774,6 +788,7 @@ class TestGCSToBigQueryOperator:
             destination_project_dataset_table=TEST_EXPLICIT_DEST,
             external_table=True,
             autodetect=None,
+            project_id=JOB_PROJECT_ID,
         )
 
         operator.execute(context=MagicMock())
@@ -781,7 +796,7 @@ class TestGCSToBigQueryOperator:
         hook.return_value.create_empty_table.assert_called_once_with(
             exists_ok=True,
             location=None,
-            project_id=PROJECT_ID,
+            project_id=JOB_PROJECT_ID,
             table_resource={
                 "tableReference": {"projectId": PROJECT_ID, "datasetId": DATASET, "tableId": TABLE},
                 "labels": {},
@@ -820,6 +835,7 @@ class TestGCSToBigQueryOperator:
             write_disposition=WRITE_DISPOSITION,
             autodetect=None,
             external_table=False,
+            project_id=JOB_PROJECT_ID,
         )
 
         operator.execute(context=MagicMock())
@@ -842,7 +858,7 @@ class TestGCSToBigQueryOperator:
                         "encoding": "UTF-8",
                     }
                 },
-                project_id=hook.return_value.split_tablename.return_value[0],
+                project_id=JOB_PROJECT_ID,
                 location=None,
                 job_id=pytest.real_job_id,
                 timeout=None,
@@ -870,6 +886,7 @@ class TestGCSToBigQueryOperator:
                 max_id_key=MAX_ID_KEY,
                 write_disposition=WRITE_DISPOSITION,
                 external_table=False,
+                project_id=JOB_PROJECT_ID,
             )
             operator.execute(context=MagicMock())
 
@@ -890,6 +907,7 @@ class TestGCSToBigQueryOperator:
                 max_id_key=MAX_ID_KEY,
                 write_disposition=WRITE_DISPOSITION,
                 external_table=False,
+                project_id=JOB_PROJECT_ID,
             )
             operator.execute(context=MagicMock())
 
@@ -912,6 +930,7 @@ class TestGCSToBigQueryOperator:
                 max_id_key=MAX_ID_KEY,
                 write_disposition=WRITE_DISPOSITION,
                 external_table=False,
+                project_id=JOB_PROJECT_ID,
             )
             operator.execute(context=MagicMock())
 
@@ -942,6 +961,7 @@ class TestGCSToBigQueryOperator:
                 external_table=False,
                 autodetect=False,
                 source_format="incorrect",
+                project_id=JOB_PROJECT_ID,
             )
             operator.execute(context=MagicMock())
 
@@ -973,6 +993,7 @@ class TestGCSToBigQueryOperator:
             max_id_key=MAX_ID_KEY,
             external_table=True,
             autodetect=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         result = operator.execute(context=MagicMock())
@@ -981,7 +1002,7 @@ class TestGCSToBigQueryOperator:
         bq_hook.return_value.create_empty_table.assert_called_once_with(
             exists_ok=True,
             location=None,
-            project_id=PROJECT_ID,
+            project_id=JOB_PROJECT_ID,
             table_resource={
                 "tableReference": {"projectId": PROJECT_ID, "datasetId": DATASET, "tableId": TABLE},
                 "labels": {},
@@ -1010,7 +1031,7 @@ class TestGCSToBigQueryOperator:
                     "schemaUpdateOptions": [],
                 }
             },
-            project_id=bq_hook.return_value.project_id,
+            project_id=JOB_PROJECT_ID,
         )
 
     @mock.patch(GCS_TO_BQ_PATH.format("GCSHook"))
@@ -1041,6 +1062,7 @@ class TestGCSToBigQueryOperator:
             max_id_key=MAX_ID_KEY,
             external_table=False,
             autodetect=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         result = operator.execute(context=MagicMock())
@@ -1067,7 +1089,7 @@ class TestGCSToBigQueryOperator:
                 job_id=pytest.real_job_id,
                 location=None,
                 nowait=True,
-                project_id=bq_hook.return_value.split_tablename.return_value[0],
+                project_id=JOB_PROJECT_ID,
                 retry=DEFAULT_RETRY,
                 timeout=None,
             ),
@@ -1079,7 +1101,7 @@ class TestGCSToBigQueryOperator:
                         "schemaUpdateOptions": [],
                     }
                 },
-                project_id=bq_hook.return_value.project_id,
+                project_id=JOB_PROJECT_ID,
             ),
         ]
 
@@ -1104,6 +1126,7 @@ class TestGCSToBigQueryOperator:
             schema_fields=SCHEMA_FIELDS_INT,
             external_table=False,
             autodetect=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         operator.execute(context=MagicMock())
@@ -1129,7 +1152,7 @@ class TestGCSToBigQueryOperator:
                 job_id=pytest.real_job_id,
                 location=None,
                 nowait=True,
-                project_id=hook.return_value.split_tablename.return_value[0],
+                project_id=JOB_PROJECT_ID,
                 retry=DEFAULT_RETRY,
                 timeout=None,
             )
@@ -1156,13 +1179,14 @@ class TestGCSToBigQueryOperator:
             schema_fields=SCHEMA_FIELDS_INT,
             external_table=True,
             autodetect=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         operator.execute(context=MagicMock())
         hook.return_value.create_empty_table.assert_called_once_with(
             exists_ok=True,
             location=None,
-            project_id=PROJECT_ID,
+            project_id=JOB_PROJECT_ID,
             table_resource={
                 "tableReference": {"projectId": PROJECT_ID, "datasetId": DATASET, "tableId": TABLE},
                 "labels": {},
@@ -1208,6 +1232,7 @@ class TestAsyncGCSToBigQueryOperator:
             external_table=False,
             autodetect=True,
             deferrable=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         with pytest.raises(TaskDeferred) as exc:
@@ -1233,6 +1258,7 @@ class TestAsyncGCSToBigQueryOperator:
                 external_table=False,
                 autodetect=True,
                 deferrable=True,
+                project_id=JOB_PROJECT_ID,
             )
             operator.execute_complete(
                 context=None, event={"status": "error", "message": "test failure message"}
@@ -1253,6 +1279,7 @@ class TestAsyncGCSToBigQueryOperator:
             external_table=False,
             autodetect=True,
             deferrable=True,
+            project_id=JOB_PROJECT_ID,
         )
         with mock.patch.object(operator.log, "info") as mock_log_info:
             operator.execute_complete(
@@ -1286,6 +1313,7 @@ class TestAsyncGCSToBigQueryOperator:
             external_table=False,
             autodetect=True,
             deferrable=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         with pytest.raises(TaskDeferred):
@@ -1326,6 +1354,7 @@ class TestAsyncGCSToBigQueryOperator:
             external_table=False,
             autodetect=True,
             deferrable=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         with pytest.raises(TaskDeferred):
@@ -1334,7 +1363,7 @@ class TestAsyncGCSToBigQueryOperator:
         hook.return_value.get_job.assert_called_once_with(
             location=TEST_DATASET_LOCATION,
             job_id=pytest.real_job_id,
-            project_id=hook.return_value.project_id,
+            project_id=JOB_PROJECT_ID,
         )
 
         job._begin.assert_called_once_with()
@@ -1365,6 +1394,7 @@ class TestAsyncGCSToBigQueryOperator:
             external_table=False,
             autodetect=True,
             deferrable=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         with pytest.raises(AirflowException) as exc:
@@ -1381,7 +1411,7 @@ class TestAsyncGCSToBigQueryOperator:
         hook.return_value.get_job.assert_called_once_with(
             location=TEST_DATASET_LOCATION,
             job_id=pytest.real_job_id,
-            project_id=hook.return_value.project_id,
+            project_id=JOB_PROJECT_ID,
         )
 
     @mock.patch(GCS_TO_BQ_PATH.format("GCSHook"))
@@ -1406,6 +1436,7 @@ class TestAsyncGCSToBigQueryOperator:
             external_table=False,
             autodetect=True,
             deferrable=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         with pytest.raises(TaskDeferred):
@@ -1437,7 +1468,7 @@ class TestAsyncGCSToBigQueryOperator:
                             schema={"fields": SCHEMA_FIELDS},
                         ),
                     },
-                    project_id=bq_hook.return_value.project_id,
+                    project_id=JOB_PROJECT_ID,
                     location=None,
                     job_id=pytest.real_job_id,
                     timeout=None,
@@ -1452,7 +1483,7 @@ class TestAsyncGCSToBigQueryOperator:
                             "schemaUpdateOptions": [],
                         }
                     },
-                    project_id=bq_hook.return_value.project_id,
+                    project_id=JOB_PROJECT_ID,
                 ),
             ]
 
@@ -1482,6 +1513,7 @@ class TestAsyncGCSToBigQueryOperator:
             external_table=False,
             autodetect=True,
             deferrable=True,
+            project_id=JOB_PROJECT_ID,
         )
 
         with pytest.raises(TaskDeferred):
@@ -1512,7 +1544,7 @@ class TestAsyncGCSToBigQueryOperator:
                             encoding="UTF-8",
                         ),
                     },
-                    project_id=bq_hook.return_value.project_id,
+                    project_id=JOB_PROJECT_ID,
                     location=None,
                     job_id=pytest.real_job_id,
                     timeout=None,
@@ -1527,7 +1559,7 @@ class TestAsyncGCSToBigQueryOperator:
                             "schemaUpdateOptions": [],
                         }
                     },
-                    project_id=bq_hook.return_value.project_id,
+                    project_id=JOB_PROJECT_ID,
                 ),
             ]