You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "shahar1 (via GitHub)" <gi...@apache.org> on 2026/02/06 16:43:16 UTC
[PR] Fix deferrable mode in CloudRunExecuteJobOperator [airflow]
shahar1 opened a new pull request, #61546:
URL: https://github.com/apache/airflow/pull/61546
<!--
Thank you for contributing!
Please provide above a brief description of the changes made in this pull request.
Write a good git commit message following this guide: http://chris.beams.io/posts/git-commit/
Please make sure that your code changes are covered with tests.
And in case of new features or big changes remember to adjust the documentation.
Feel free to ping (in general) for the review if you do not see reaction for a few days
(72 Hours is the minimum reaction time you can expect from volunteers) - we sometimes miss notifications.
In case of an existing issue, reference it using one of the following:
* closes: #ISSUE
* related: #ISSUE
-->
---
##### Was generative AI tooling used to co-author this PR?
<!--
If generative AI tooling has been used in the process of authoring this PR, please
change below checkbox to `[X]` followed by the name of the tool, uncomment the "Generated-by".
-->
related: #60394
- [X] Yes (please specify the tool below)
Claude Sonnet 4.5
<!--
Generated-by: [Tool Name] following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
-->
---
* Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
* For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment: `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix deferrable mode in CloudRunExecuteJobOperator [airflow]
Posted by "dabla (via GitHub)" <gi...@apache.org>.
dabla commented on code in PR #61546:
URL: https://github.com/apache/airflow/pull/61546#discussion_r2784148376
##########
providers/google/tests/unit/google/cloud/hooks/test_cloud_run.py:
##########
@@ -293,6 +308,56 @@ async def test_get_operation(self):
operations_pb2.GetOperationRequest(name=OPERATION_NAME), timeout=120
)
+ @pytest.mark.asyncio
+ @mock.patch("airflow.providers.google.cloud.hooks.cloud_run.JobsAsyncClient")
+ async def test_get_conn_uses_async_client_by_default(self, mock_async_client):
+ """Test that get_conn uses JobsAsyncClient (grpc_asyncio) when transport is None or grpc."""
+ hook = CloudRunAsyncHook(transport=None)
+ mock_sync_hook = mock.MagicMock()
Review Comment:
I would spec that MagicMock(spec=CloudRunServiceHook) here with the class of the sync hook
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix deferrable mode in CloudRunExecuteJobOperator [airflow]
Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on code in PR #61546:
URL: https://github.com/apache/airflow/pull/61546#discussion_r2784116574
##########
providers/google/tests/system/google/cloud/cloud_run/example_cloud_run.py:
##########
@@ -285,6 +325,28 @@ def _create_job_instance_with_label():
)
# [END howto_operator_cloud_run_execute_job_with_overrides]
+ execute4 = CloudRunExecuteJobOperator(
+ task_id=execute4_task_name,
+ project_id=PROJECT_ID,
+ region=region,
+ job_name=job4_name,
+ dag=dag,
+ deferrable=False,
+ transport="rest",
+ )
+
+ # [START howto_operator_cloud_run_execute_job_deferrable_rest]
Review Comment:
I'll assume that you meant to tag me :)
I'll handle it after GitHub's issue is solved
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix deferrable mode in CloudRunExecuteJobOperator [airflow]
Posted by "olegkachur-e (via GitHub)" <gi...@apache.org>.
olegkachur-e commented on code in PR #61546:
URL: https://github.com/apache/airflow/pull/61546#discussion_r2783262840
##########
providers/google/tests/unit/google/cloud/hooks/test_cloud_run.py:
##########
@@ -264,16 +264,31 @@ def test_delete_job(self, mock_batch_service_client, cloud_run_hook):
new=mock_base_gcp_hook_default_project_id,
)
@mock.patch("airflow.providers.google.cloud.hooks.cloud_run.JobsClient")
- @pytest.mark.parametrize(("transport", "expected_transport"), [("rest", "rest"), (None, None)])
- def test_get_conn_with_transport(self, mock_jobs_client, transport, expected_transport):
+ @pytest.mark.parametrize("transport", ["rest"])
Review Comment:
nit: Do we still need parametrize here? Is it worth adding more transport values tested?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix deferrable mode in CloudRunExecuteJobOperator [airflow]
Posted by "dabla (via GitHub)" <gi...@apache.org>.
dabla commented on code in PR #61546:
URL: https://github.com/apache/airflow/pull/61546#discussion_r2784149216
##########
providers/google/tests/unit/google/cloud/hooks/test_cloud_run.py:
##########
@@ -293,6 +308,56 @@ async def test_get_operation(self):
operations_pb2.GetOperationRequest(name=OPERATION_NAME), timeout=120
)
+ @pytest.mark.asyncio
+ @mock.patch("airflow.providers.google.cloud.hooks.cloud_run.JobsAsyncClient")
+ async def test_get_conn_uses_async_client_by_default(self, mock_async_client):
+ """Test that get_conn uses JobsAsyncClient (grpc_asyncio) when transport is None or grpc."""
+ hook = CloudRunAsyncHook(transport=None)
+ mock_sync_hook = mock.MagicMock()
+ mock_sync_hook.get_credentials.return_value = "credentials"
+ hook.get_sync_hook = mock.AsyncMock(return_value=mock_sync_hook)
+
+ await hook.get_conn()
+
+ mock_async_client.assert_called_once()
+ call_kwargs = mock_async_client.call_args[1]
+ assert "transport" not in call_kwargs
+
+ @pytest.mark.asyncio
+ @mock.patch("airflow.providers.google.cloud.hooks.cloud_run.JobsClient")
+ async def test_get_conn_uses_sync_client_for_rest(self, mock_sync_client):
+ """Test that get_conn uses sync JobsClient with REST transport."""
+ hook = CloudRunAsyncHook(transport="rest")
+ mock_sync_hook = mock.MagicMock()
Review Comment:
Same here, MagicMock(spec=CloudRunServiceHook)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix deferrable mode in CloudRunExecuteJobOperator [airflow]
Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 merged PR #61546:
URL: https://github.com/apache/airflow/pull/61546
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix deferrable mode in CloudRunExecuteJobOperator [airflow]
Posted by "dabla (via GitHub)" <gi...@apache.org>.
dabla commented on code in PR #61546:
URL: https://github.com/apache/airflow/pull/61546#discussion_r2784159047
##########
providers/google/tests/unit/google/cloud/hooks/test_cloud_run.py:
##########
@@ -293,6 +308,56 @@ async def test_get_operation(self):
operations_pb2.GetOperationRequest(name=OPERATION_NAME), timeout=120
)
+ @pytest.mark.asyncio
+ @mock.patch("airflow.providers.google.cloud.hooks.cloud_run.JobsAsyncClient")
+ async def test_get_conn_uses_async_client_by_default(self, mock_async_client):
+ """Test that get_conn uses JobsAsyncClient (grpc_asyncio) when transport is None or grpc."""
+ hook = CloudRunAsyncHook(transport=None)
+ mock_sync_hook = mock.MagicMock()
+ mock_sync_hook.get_credentials.return_value = "credentials"
+ hook.get_sync_hook = mock.AsyncMock(return_value=mock_sync_hook)
+
+ await hook.get_conn()
+
+ mock_async_client.assert_called_once()
+ call_kwargs = mock_async_client.call_args[1]
+ assert "transport" not in call_kwargs
+
+ @pytest.mark.asyncio
+ @mock.patch("airflow.providers.google.cloud.hooks.cloud_run.JobsClient")
+ async def test_get_conn_uses_sync_client_for_rest(self, mock_sync_client):
+ """Test that get_conn uses sync JobsClient with REST transport."""
+ hook = CloudRunAsyncHook(transport="rest")
+ mock_sync_hook = mock.MagicMock()
+ mock_sync_hook.get_credentials.return_value = "credentials"
+ hook.get_sync_hook = mock.AsyncMock(return_value=mock_sync_hook)
+
+ await hook.get_conn()
+
+ mock_sync_client.assert_called_once()
+ call_kwargs = mock_sync_client.call_args[1]
+ assert call_kwargs["transport"] == "rest"
+
+ @pytest.mark.asyncio
+ @mock.patch("asyncio.to_thread")
+ async def test_get_operation_rest_uses_to_thread(self, mock_to_thread):
+ """Test that get_operation uses asyncio.to_thread for REST transport."""
+ expected_operation = operations_pb2.Operation(name=OPERATION_NAME)
+ mock_to_thread.return_value = expected_operation
+
+ hook = CloudRunAsyncHook(transport="rest")
+ mock_conn = mock.MagicMock() # sync client
+ hook.get_conn = mock.AsyncMock(return_value=mock_conn)
+
+ result = await hook.get_operation(operation_name=OPERATION_NAME)
+
+ mock_to_thread.assert_called_once_with(
+ mock_conn.get_operation,
+ operations_pb2.GetOperationRequest(name=OPERATION_NAME),
+ timeout=120,
+ )
+ assert result == expected_operation
+
def mock_get_operation(self, expected_operation):
Review Comment:
type the expected_operation as operations_pb2.Operation and also add spec to get_operation AsyncMock(spec=operations_pb2.Operation)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix deferrable mode in CloudRunExecuteJobOperator [airflow]
Posted by "dabla (via GitHub)" <gi...@apache.org>.
dabla commented on code in PR #61546:
URL: https://github.com/apache/airflow/pull/61546#discussion_r2784152228
##########
providers/google/tests/unit/google/cloud/hooks/test_cloud_run.py:
##########
@@ -293,6 +308,56 @@ async def test_get_operation(self):
operations_pb2.GetOperationRequest(name=OPERATION_NAME), timeout=120
)
+ @pytest.mark.asyncio
+ @mock.patch("airflow.providers.google.cloud.hooks.cloud_run.JobsAsyncClient")
+ async def test_get_conn_uses_async_client_by_default(self, mock_async_client):
+ """Test that get_conn uses JobsAsyncClient (grpc_asyncio) when transport is None or grpc."""
+ hook = CloudRunAsyncHook(transport=None)
+ mock_sync_hook = mock.MagicMock()
+ mock_sync_hook.get_credentials.return_value = "credentials"
+ hook.get_sync_hook = mock.AsyncMock(return_value=mock_sync_hook)
+
+ await hook.get_conn()
+
+ mock_async_client.assert_called_once()
+ call_kwargs = mock_async_client.call_args[1]
+ assert "transport" not in call_kwargs
+
+ @pytest.mark.asyncio
+ @mock.patch("airflow.providers.google.cloud.hooks.cloud_run.JobsClient")
+ async def test_get_conn_uses_sync_client_for_rest(self, mock_sync_client):
+ """Test that get_conn uses sync JobsClient with REST transport."""
+ hook = CloudRunAsyncHook(transport="rest")
+ mock_sync_hook = mock.MagicMock()
+ mock_sync_hook.get_credentials.return_value = "credentials"
+ hook.get_sync_hook = mock.AsyncMock(return_value=mock_sync_hook)
+
+ await hook.get_conn()
+
+ mock_sync_client.assert_called_once()
+ call_kwargs = mock_sync_client.call_args[1]
+ assert call_kwargs["transport"] == "rest"
+
+ @pytest.mark.asyncio
+ @mock.patch("asyncio.to_thread")
+ async def test_get_operation_rest_uses_to_thread(self, mock_to_thread):
+ """Test that get_operation uses asyncio.to_thread for REST transport."""
+ expected_operation = operations_pb2.Operation(name=OPERATION_NAME)
+ mock_to_thread.return_value = expected_operation
+
+ hook = CloudRunAsyncHook(transport="rest")
+ mock_conn = mock.MagicMock() # sync client
Review Comment:
Could also be a MagicMock(spec=ServicesClient)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix deferrable mode in CloudRunExecuteJobOperator [airflow]
Posted by "MaksYermak (via GitHub)" <gi...@apache.org>.
MaksYermak commented on code in PR #61546:
URL: https://github.com/apache/airflow/pull/61546#discussion_r2782110602
##########
providers/google/tests/system/google/cloud/cloud_run/example_cloud_run.py:
##########
@@ -285,6 +325,28 @@ def _create_job_instance_with_label():
)
# [END howto_operator_cloud_run_execute_job_with_overrides]
+ execute4 = CloudRunExecuteJobOperator(
+ task_id=execute4_task_name,
+ project_id=PROJECT_ID,
+ region=region,
+ job_name=job4_name,
+ dag=dag,
+ deferrable=False,
+ transport="rest",
+ )
+
+ # [START howto_operator_cloud_run_execute_job_deferrable_rest]
Review Comment:
@eladkal could you remove this tag or add to the documentation, because in the current time I do not see any usage of this tag?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix deferrable mode in CloudRunExecuteJobOperator [airflow]
Posted by "MaksYermak (via GitHub)" <gi...@apache.org>.
MaksYermak commented on code in PR #61546:
URL: https://github.com/apache/airflow/pull/61546#discussion_r2786699133
##########
providers/google/tests/system/google/cloud/cloud_run/example_cloud_run.py:
##########
@@ -285,6 +325,28 @@ def _create_job_instance_with_label():
)
# [END howto_operator_cloud_run_execute_job_with_overrides]
+ execute4 = CloudRunExecuteJobOperator(
+ task_id=execute4_task_name,
+ project_id=PROJECT_ID,
+ region=region,
+ job_name=job4_name,
+ dag=dag,
+ deferrable=False,
+ transport="rest",
+ )
+
+ # [START howto_operator_cloud_run_execute_job_deferrable_rest]
Review Comment:
Sorry, yes sure I wanted to tag you :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix deferrable mode in CloudRunExecuteJobOperator [airflow]
Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on code in PR #61546:
URL: https://github.com/apache/airflow/pull/61546#discussion_r2784115901
##########
providers/google/tests/unit/google/cloud/hooks/test_cloud_run.py:
##########
@@ -264,16 +264,31 @@ def test_delete_job(self, mock_batch_service_client, cloud_run_hook):
new=mock_base_gcp_hook_default_project_id,
)
@mock.patch("airflow.providers.google.cloud.hooks.cloud_run.JobsClient")
- @pytest.mark.parametrize(("transport", "expected_transport"), [("rest", "rest"), (None, None)])
- def test_get_conn_with_transport(self, mock_jobs_client, transport, expected_transport):
+ @pytest.mark.parametrize("transport", ["rest"])
Review Comment:
for the unit test - maybe a `None` to test the other case of the `if` statement. I'll handle it before merging (GitHub is currently stuck)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix deferrable mode in CloudRunExecuteJobOperator [airflow]
Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on code in PR #61546:
URL: https://github.com/apache/airflow/pull/61546#discussion_r2786166324
##########
providers/google/tests/unit/google/cloud/hooks/test_cloud_run.py:
##########
@@ -293,6 +308,56 @@ async def test_get_operation(self):
operations_pb2.GetOperationRequest(name=OPERATION_NAME), timeout=120
)
+ @pytest.mark.asyncio
+ @mock.patch("airflow.providers.google.cloud.hooks.cloud_run.JobsAsyncClient")
+ async def test_get_conn_uses_async_client_by_default(self, mock_async_client):
+ """Test that get_conn uses JobsAsyncClient (grpc_asyncio) when transport is None or grpc."""
+ hook = CloudRunAsyncHook(transport=None)
+ mock_sync_hook = mock.MagicMock()
+ mock_sync_hook.get_credentials.return_value = "credentials"
+ hook.get_sync_hook = mock.AsyncMock(return_value=mock_sync_hook)
+
+ await hook.get_conn()
+
+ mock_async_client.assert_called_once()
+ call_kwargs = mock_async_client.call_args[1]
+ assert "transport" not in call_kwargs
+
+ @pytest.mark.asyncio
+ @mock.patch("airflow.providers.google.cloud.hooks.cloud_run.JobsClient")
+ async def test_get_conn_uses_sync_client_for_rest(self, mock_sync_client):
+ """Test that get_conn uses sync JobsClient with REST transport."""
+ hook = CloudRunAsyncHook(transport="rest")
+ mock_sync_hook = mock.MagicMock()
+ mock_sync_hook.get_credentials.return_value = "credentials"
+ hook.get_sync_hook = mock.AsyncMock(return_value=mock_sync_hook)
+
+ await hook.get_conn()
+
+ mock_sync_client.assert_called_once()
+ call_kwargs = mock_sync_client.call_args[1]
+ assert call_kwargs["transport"] == "rest"
+
+ @pytest.mark.asyncio
+ @mock.patch("asyncio.to_thread")
+ async def test_get_operation_rest_uses_to_thread(self, mock_to_thread):
+ """Test that get_operation uses asyncio.to_thread for REST transport."""
+ expected_operation = operations_pb2.Operation(name=OPERATION_NAME)
+ mock_to_thread.return_value = expected_operation
+
+ hook = CloudRunAsyncHook(transport="rest")
+ mock_conn = mock.MagicMock() # sync client
+ hook.get_conn = mock.AsyncMock(return_value=mock_conn)
+
+ result = await hook.get_operation(operation_name=OPERATION_NAME)
+
+ mock_to_thread.assert_called_once_with(
+ mock_conn.get_operation,
+ operations_pb2.GetOperationRequest(name=OPERATION_NAME),
+ timeout=120,
+ )
+ assert result == expected_operation
+
def mock_get_operation(self, expected_operation):
Review Comment:
Seems to be like a dead code that could be removed anyway :D
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org