diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8fcfd4c431c9a..c587912a8a14b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -329,7 +329,6 @@ repos: ^airflow\/providers\/databricks\/operators\/databricks\.py$| ^airflow\/providers\/google\/cloud\/transfers\/bigquery_to_mysql\.py$| ^airflow\/providers\/amazon\/aws\/transfers\/redshift_to_s3\.py$| - ^airflow\/providers\/google\/cloud\/operators\/compute\.py$| ^airflow\/providers\/amazon\/aws\/operators\/emr\.py$| ^airflow\/providers\/amazon\/aws\/operators\/eks\.py$ )$ diff --git a/airflow/providers/google/cloud/links/compute.py b/airflow/providers/google/cloud/links/compute.py index 3c27cd18649d3..62eeaa6967ffa 100644 --- a/airflow/providers/google/cloud/links/compute.py +++ b/airflow/providers/google/cloud/links/compute.py @@ -48,7 +48,7 @@ def persist( context: Context, task_instance: BaseOperator, location_id: str, - resource_id: str, + resource_id: str | None, project_id: str | None, ): task_instance.xcom_push( @@ -73,7 +73,7 @@ class ComputeInstanceTemplateDetailsLink(BaseGoogleLink): def persist( context: Context, task_instance: BaseOperator, - resource_id: str, + resource_id: str | None, project_id: str | None, ): task_instance.xcom_push( @@ -98,7 +98,7 @@ def persist( context: Context, task_instance: BaseOperator, location_id: str, - resource_id: str, + resource_id: str | None, project_id: str | None, ): task_instance.xcom_push( diff --git a/airflow/providers/google/cloud/operators/compute.py b/airflow/providers/google/cloud/operators/compute.py index 1dfd50a46437f..ec7187e5988ad 100644 --- a/airflow/providers/google/cloud/operators/compute.py +++ b/airflow/providers/google/cloud/operators/compute.py @@ -49,7 +49,7 @@ def __init__( self, *, zone: str, - resource_id: str, + resource_id: str | None = None, project_id: str | None = None, gcp_conn_id: str = "google_cloud_default", api_version: str = "v1", @@ -151,7 +151,8 @@ def __init__( self.body = body self.zone = zone self.request_id = request_id - self.resource_id = self.body["name"] if "name" in body else resource_id + if "name" in body: + resource_id = self.body["name"] self._field_validator = None # Optional[GcpBodyFieldValidator] self.retry = retry self.timeout = timeout @@ -163,7 +164,7 @@ def __init__( ) self._field_sanitizer = GcpBodyFieldSanitizer(GCE_INSTANCE_FIELDS_TO_SANITIZE) super().__init__( - resource_id=self.resource_id, + resource_id=resource_id, zone=zone, project_id=project_id, gcp_conn_id=gcp_conn_id, @@ -332,7 +333,8 @@ def __init__( self.source_instance_template = source_instance_template self.body = body self.zone = zone - self.resource_id = self.body["name"] if "name" in body else resource_id + if "name" in body: + resource_id = self.body["name"] self.request_id = request_id self._field_validator = None # Optional[GcpBodyFieldValidator] self.retry = retry @@ -345,7 +347,7 @@ def __init__( ) self._field_sanitizer = GcpBodyFieldSanitizer(GCE_INSTANCE_FIELDS_TO_SANITIZE) super().__init__( - resource_id=self.resource_id, + resource_id=resource_id, zone=zone, project_id=project_id, gcp_conn_id=gcp_conn_id, @@ -893,7 +895,8 @@ def __init__( ) -> None: self.body = body self.request_id = request_id - self.resource_id = self.body["name"] if "name" in body else resource_id + if "name" in body: + resource_id = self.body["name"] self._field_validator = None # Optional[GcpBodyFieldValidator] self.retry = retry self.timeout = timeout @@ -907,7 +910,7 @@ def __init__( super().__init__( project_id=project_id, zone="global", - resource_id=self.resource_id, + resource_id=resource_id, gcp_conn_id=gcp_conn_id, api_version=api_version, impersonation_chain=impersonation_chain, @@ -1341,7 +1344,7 @@ def __init__( ) super().__init__( project_id=project_id, - zone=self.zone, + zone=zone, resource_id=resource_id, gcp_conn_id=gcp_conn_id, api_version=api_version, @@ -1477,9 +1480,9 @@ def __init__( **kwargs, ) -> None: self.body = body - self.zone = zone self.request_id = request_id - self.resource_id = self.body["name"] if "name" in body else resource_id + if "name" in body: + resource_id = self.body["name"] self._field_validator = None # Optional[GcpBodyFieldValidator] self.retry = retry self.timeout = timeout @@ -1492,7 +1495,7 @@ def __init__( super().__init__( project_id=project_id, zone=zone, - resource_id=self.resource_id, + resource_id=resource_id, gcp_conn_id=gcp_conn_id, api_version=api_version, impersonation_chain=impersonation_chain,