@@ -4425,6 +4425,57 @@ async def test_workflow_update_task_fails(client: Client, env: WorkflowEnvironme
44254425 assert bad_validator_fail_ct == 2
44264426
44274427
4428+ @workflow .defn
4429+ class UpdateRespectsFirstExecutionRunIdWorkflow :
4430+ def __init__ (self ) -> None :
4431+ self .update_received = False
4432+
4433+ @workflow .run
4434+ async def run (self ) -> None :
4435+ await workflow .wait_condition (lambda : self .update_received )
4436+
4437+ @workflow .update
4438+ async def update (self ) -> None :
4439+ self .update_received = True
4440+
4441+
4442+ async def test_workflow_update_respects_first_execution_run_id (
4443+ client : Client , env : WorkflowEnvironment
4444+ ):
4445+ if env .supports_time_skipping :
4446+ pytest .skip (
4447+ "Java test server: https://github.com/temporalio/sdk-java/issues/1903"
4448+ )
4449+ # Start one workflow, obtain the run ID (r1), and let it complete. Start a second
4450+ # workflow with the same workflow ID, and try to send an update using the handle from
4451+ # r1.
4452+ workflow_id = f"update-respects-first-execution-run-id-{ uuid .uuid4 ()} "
4453+ async with new_worker (client , UpdateRespectsFirstExecutionRunIdWorkflow ) as worker :
4454+
4455+ async def start_workflow (workflow_id : str ) -> WorkflowHandle :
4456+ return await client .start_workflow (
4457+ UpdateRespectsFirstExecutionRunIdWorkflow .run ,
4458+ id = workflow_id ,
4459+ task_queue = worker .task_queue ,
4460+ )
4461+
4462+ wf_execution_1_handle = await start_workflow (workflow_id )
4463+ await wf_execution_1_handle .execute_update (
4464+ UpdateRespectsFirstExecutionRunIdWorkflow .update
4465+ )
4466+ await wf_execution_1_handle .result ()
4467+ await start_workflow (workflow_id )
4468+
4469+ # Execution 1 has closed. This would succeed if the update incorrectly targets
4470+ # the second execution
4471+ with pytest .raises (RPCError ) as exc_info :
4472+ await wf_execution_1_handle .execute_update (
4473+ UpdateRespectsFirstExecutionRunIdWorkflow .update
4474+ )
4475+ assert exc_info .value .status == RPCStatusCode .NOT_FOUND
4476+ assert "workflow execution not found" in str (exc_info .value )
4477+
4478+
44284479@workflow .defn
44294480class ImmediatelyCompleteUpdateAndWorkflow :
44304481 def __init__ (self ) -> None :
0 commit comments