Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions temporalio/worker/_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,11 +731,13 @@ def client(self, value: temporalio.client.Client) -> None:

Changing the client will make sure the worker starts using it for the
next calls it makes. However, outstanding client calls will still
complete with the existing client. The new client cannot be "lazy" and
must be using the same runtime as the current client.
complete with the existing client. The new client cannot be "lazy" and,
when configured with an explicit runtime, must use the current client's
runtime.
"""
bridge_client = _extract_bridge_client_for_worker(value)
if self._runtime is not bridge_client.config.runtime:
new_runtime = bridge_client.config.runtime
if new_runtime is not None and self._runtime is not new_runtime:
raise ValueError(
"New client is not on the same runtime as the existing client"
)
Expand Down
16 changes: 16 additions & 0 deletions tests/worker/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6279,6 +6279,22 @@ async def test_workflow_replace_worker_client_diff_runtimes_fail(
worker.client = other_client


async def test_workflow_replace_worker_client_implicit_runtime(
env: WorkflowEnvironment,
):
# An implicit runtime must not be resolved just to compare it with the
# worker's explicit runtime. The worker owns the runtime for its bridge
# client replacement.
worker_runtime = Runtime(telemetry=TelemetryConfig())
worker_client = await env.connect_client(runtime=worker_runtime)
default_runtime_client = await Client.connect(
worker_client.service_client.config.target_host,
namespace=worker_client.namespace,
)
async with new_worker(worker_client, HelloWorkflow) as worker:
worker.client = default_runtime_client


@activity.defn(dynamic=True)
async def return_name_activity(_args: Sequence[RawValue]) -> str:
return activity.info().activity_type
Expand Down