You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ephraimbuddy (via GitHub)" <gi...@apache.org> on 2026/04/27 20:43:37 UTC

[PR] Extract Client factory from TriggerRunnerSupervisor into overridable method [airflow]

ephraimbuddy opened a new pull request, #65978:
URL: https://github.com/apache/airflow/pull/65978

   Splits the in-process Client construction out of the cached_property into a separate make_client() method so subclasses can override how the Client is built while still benefiting from the cached_property.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [x] Yes (please specify the tool below)
   
   Generated-by:  claude code (opus 4.7)
   
   


-- 
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] Extract Client factory from TriggerRunnerSupervisor into overridable method [airflow]

Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #65978:
URL: https://github.com/apache/airflow/pull/65978#discussion_r3153653424


##########
airflow-core/src/airflow/jobs/triggerer_job_runner.py:
##########
@@ -447,6 +447,9 @@ def start(  # type: ignore[override]
 
     @functools.cached_property
     def client(self) -> Client:
+        return self.make_client()
+
+    def make_client(self) -> Client:

Review Comment:
   Worth a short docstring on `make_client` spelling out the override contract: must return a `Client` whose `base_url` is set (downstream `_handle_request` paths call `self.client.variables`, `.xcoms`, etc. and inherit the URL), and likely `dry_run=True` if the subclass is also using the in-process transport. Without an in-tree subclass it's hard for future maintainers to know which of these defaults are load-bearing vs incidental.



##########
airflow-core/tests/unit/jobs/test_triggerer_job.py:
##########
@@ -260,6 +260,38 @@ def fake_run_once(self):
     assert events == ["enter", "tick-1", "tick-2", "tick-3", "exit"]
 
 
+def test_make_client_builds_in_process_client(supervisor_builder, mocker):
+    supervisor = supervisor_builder()
+    api_server = mocker.Mock(transport=mocker.sentinel.transport)
+    client = mocker.Mock()

Review Comment:
   These mocks could use `spec`. `client = mocker.Mock()` and `mocker.Mock(transport=...)` happily accept any kwargs, so if `Client.__init__` renames `base_url` to `url` (or `transport` moves), the test stays green while production breaks. `mocker.Mock(spec=Client)` would catch that. The second test already uses `autospec=True` on the `patch.object` -- same idea.
   
   Optionally these two tests could collapse into one that defines a subclass overriding `make_client` to return a sentinel and asserts `supervisor.client is sentinel` -- that covers delegation, caching, and the actual subclass-override use case the PR is built for, in one shot. Happy to leave as-is though.



-- 
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] Extract Client factory from TriggerRunnerSupervisor into overridable method [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #65978:
URL: https://github.com/apache/airflow/pull/65978#discussion_r3152678444


##########
airflow-core/src/airflow/jobs/triggerer_job_runner.py:
##########
@@ -447,6 +447,9 @@ def start(  # type: ignore[override]
 
     @functools.cached_property
     def client(self) -> Client:
+        return self.make_client()
+
+    def make_client(self) -> Client:

Review Comment:
   Should this be `_make_client` instead? (Not public)



-- 
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] Extract Client factory from TriggerRunnerSupervisor into overridable method [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #65978:
URL: https://github.com/apache/airflow/pull/65978#discussion_r3152776670


##########
airflow-core/tests/unit/jobs/test_triggerer_job.py:
##########
@@ -260,6 +260,38 @@ def fake_run_once(self):
     assert events == ["enter", "tick-1", "tick-2", "tick-3", "exit"]
 
 
+def test_make_client_builds_in_process_client(supervisor_builder, mocker):
+    supervisor = supervisor_builder()
+    api_server = mocker.Mock(transport=mocker.sentinel.transport)
+    client = mocker.Mock()
+    client_cls = mocker.patch("airflow.sdk.api.client.Client", return_value=client)
+    mocker.patch("airflow.jobs.triggerer_job_runner.in_process_api_server", return_value=api_server)
+
+    assert supervisor.make_client() is client
+
+    client_cls.assert_called_once_with(
+        base_url=None,
+        token="",
+        dry_run=True,
+        transport=mocker.sentinel.transport,
+    )
+    assert client.base_url == "http://in-process.invalid./"
+
+
+def test_client_delegates_to_make_client_and_caches_result(supervisor_builder, mocker):
+    supervisor = supervisor_builder()
+    make_client = mocker.patch.object(
+        TriggerRunnerSupervisor,
+        "make_client",
+        autospec=True,
+        return_value=mocker.sentinel.client,
+    )
+
+    assert supervisor.client is mocker.sentinel.client
+    assert supervisor.client is mocker.sentinel.client

Review Comment:
   ```suggestion
       assert supervisor.client is mocker.sentinel.client
   ```
   
   



-- 
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] Extract Client factory from TriggerRunnerSupervisor into overridable method [airflow]

Posted by "ephraimbuddy (via GitHub)" <gi...@apache.org>.
ephraimbuddy commented on code in PR #65978:
URL: https://github.com/apache/airflow/pull/65978#discussion_r3160706987


##########
airflow-core/src/airflow/jobs/triggerer_job_runner.py:
##########
@@ -447,6 +447,9 @@ def start(  # type: ignore[override]
 
     @functools.cached_property
     def client(self) -> Client:
+        return self.make_client()
+
+    def make_client(self) -> Client:

Review Comment:
   If we make it private, it will defeat the purpose of the PR which is to have overridable way of providing a client. Making it public was so that subclasses can override it without overriding the client itself



-- 
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] Extract Client factory from TriggerRunnerSupervisor into overridable method [airflow]

Posted by "ephraimbuddy (via GitHub)" <gi...@apache.org>.
ephraimbuddy merged PR #65978:
URL: https://github.com/apache/airflow/pull/65978


-- 
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] Extract Client factory from TriggerRunnerSupervisor into overridable method [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #65978:
URL: https://github.com/apache/airflow/pull/65978#discussion_r3152799977


##########
airflow-core/tests/unit/jobs/test_triggerer_job.py:
##########
@@ -260,6 +260,38 @@ def fake_run_once(self):
     assert events == ["enter", "tick-1", "tick-2", "tick-3", "exit"]
 
 
+def test_make_client_builds_in_process_client(supervisor_builder, mocker):
+    supervisor = supervisor_builder()
+    api_server = mocker.Mock(transport=mocker.sentinel.transport)
+    client = mocker.Mock()
+    client_cls = mocker.patch("airflow.sdk.api.client.Client", return_value=client)
+    mocker.patch("airflow.jobs.triggerer_job_runner.in_process_api_server", return_value=api_server)
+
+    assert supervisor.make_client() is client
+
+    client_cls.assert_called_once_with(
+        base_url=None,
+        token="",
+        dry_run=True,
+        transport=mocker.sentinel.transport,
+    )
+    assert client.base_url == "http://in-process.invalid./"
+
+
+def test_client_delegates_to_make_client_and_caches_result(supervisor_builder, mocker):
+    supervisor = supervisor_builder()
+    make_client = mocker.patch.object(
+        TriggerRunnerSupervisor,
+        "make_client",
+        autospec=True,
+        return_value=mocker.sentinel.client,
+    )
+
+    assert supervisor.client is mocker.sentinel.client
+    assert supervisor.client is mocker.sentinel.client

Review Comment:
   ```suggestion
       first  = supervisor.client
       second = supervisor.client
   
       assert first is second is mocker.sentinel.client  # cached — same object
   ```
   
   might be easier to understand this way



-- 
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] Extract Client factory from TriggerRunnerSupervisor into overridable method [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #65978:
URL: https://github.com/apache/airflow/pull/65978#discussion_r3152776670


##########
airflow-core/tests/unit/jobs/test_triggerer_job.py:
##########
@@ -260,6 +260,38 @@ def fake_run_once(self):
     assert events == ["enter", "tick-1", "tick-2", "tick-3", "exit"]
 
 
+def test_make_client_builds_in_process_client(supervisor_builder, mocker):
+    supervisor = supervisor_builder()
+    api_server = mocker.Mock(transport=mocker.sentinel.transport)
+    client = mocker.Mock()
+    client_cls = mocker.patch("airflow.sdk.api.client.Client", return_value=client)
+    mocker.patch("airflow.jobs.triggerer_job_runner.in_process_api_server", return_value=api_server)
+
+    assert supervisor.make_client() is client
+
+    client_cls.assert_called_once_with(
+        base_url=None,
+        token="",
+        dry_run=True,
+        transport=mocker.sentinel.transport,
+    )
+    assert client.base_url == "http://in-process.invalid./"
+
+
+def test_client_delegates_to_make_client_and_caches_result(supervisor_builder, mocker):
+    supervisor = supervisor_builder()
+    make_client = mocker.patch.object(
+        TriggerRunnerSupervisor,
+        "make_client",
+        autospec=True,
+        return_value=mocker.sentinel.client,
+    )
+
+    assert supervisor.client is mocker.sentinel.client
+    assert supervisor.client is mocker.sentinel.client

Review Comment:
   ```suggestion
       assert supervisor.client is mocker.sentinel.client
   ```
   
   



-- 
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