11# This file is generated by gen_payload_visitor.py. Changes should be made there.
22import abc
3+ import contextvars
34from typing import Any , MutableSequence
45
56from temporalio .api .common .v1 .message_pb2 import Payload
67
8+ # Context variable for tracking the current workflow command sequence number
9+ current_command_seq : contextvars .ContextVar [int | None ] = contextvars .ContextVar (
10+ "current_command_seq" , default = None
11+ )
12+
713
814class VisitorFunctions (abc .ABC ):
915 """Set of functions which can be called by the visitor.
@@ -371,9 +377,13 @@ async def _visit_coresdk_workflow_commands_WorkflowCommand(self, fs, o):
371377 if o .HasField ("user_metadata" ):
372378 await self ._visit_temporal_api_sdk_v1_UserMetadata (fs , o .user_metadata )
373379 if o .HasField ("schedule_activity" ):
374- await self ._visit_coresdk_workflow_commands_ScheduleActivity (
375- fs , o .schedule_activity
376- )
380+ token = current_command_seq .set (o .schedule_activity .seq )
381+ try :
382+ await self ._visit_coresdk_workflow_commands_ScheduleActivity (
383+ fs , o .schedule_activity
384+ )
385+ finally :
386+ current_command_seq .reset (token )
377387 elif o .HasField ("respond_to_query" ):
378388 await self ._visit_coresdk_workflow_commands_QueryResult (
379389 fs , o .respond_to_query
@@ -391,17 +401,29 @@ async def _visit_coresdk_workflow_commands_WorkflowCommand(self, fs, o):
391401 fs , o .continue_as_new_workflow_execution
392402 )
393403 elif o .HasField ("start_child_workflow_execution" ):
394- await self ._visit_coresdk_workflow_commands_StartChildWorkflowExecution (
395- fs , o .start_child_workflow_execution
396- )
404+ token = current_command_seq .set (o .start_child_workflow_execution .seq )
405+ try :
406+ await self ._visit_coresdk_workflow_commands_StartChildWorkflowExecution (
407+ fs , o .start_child_workflow_execution
408+ )
409+ finally :
410+ current_command_seq .reset (token )
397411 elif o .HasField ("signal_external_workflow_execution" ):
398- await self ._visit_coresdk_workflow_commands_SignalExternalWorkflowExecution (
399- fs , o .signal_external_workflow_execution
400- )
412+ token = current_command_seq .set (o .signal_external_workflow_execution .seq )
413+ try :
414+ await self ._visit_coresdk_workflow_commands_SignalExternalWorkflowExecution (
415+ fs , o .signal_external_workflow_execution
416+ )
417+ finally :
418+ current_command_seq .reset (token )
401419 elif o .HasField ("schedule_local_activity" ):
402- await self ._visit_coresdk_workflow_commands_ScheduleLocalActivity (
403- fs , o .schedule_local_activity
404- )
420+ token = current_command_seq .set (o .schedule_local_activity .seq )
421+ try :
422+ await self ._visit_coresdk_workflow_commands_ScheduleLocalActivity (
423+ fs , o .schedule_local_activity
424+ )
425+ finally :
426+ current_command_seq .reset (token )
405427 elif o .HasField ("upsert_workflow_search_attributes" ):
406428 await self ._visit_coresdk_workflow_commands_UpsertWorkflowSearchAttributes (
407429 fs , o .upsert_workflow_search_attributes
@@ -415,9 +437,13 @@ async def _visit_coresdk_workflow_commands_WorkflowCommand(self, fs, o):
415437 fs , o .update_response
416438 )
417439 elif o .HasField ("schedule_nexus_operation" ):
418- await self ._visit_coresdk_workflow_commands_ScheduleNexusOperation (
419- fs , o .schedule_nexus_operation
420- )
440+ token = current_command_seq .set (o .schedule_nexus_operation .seq )
441+ try :
442+ await self ._visit_coresdk_workflow_commands_ScheduleNexusOperation (
443+ fs , o .schedule_nexus_operation
444+ )
445+ finally :
446+ current_command_seq .reset (token )
421447
422448 async def _visit_coresdk_workflow_completion_Success (self , fs , o ):
423449 for v in o .commands :
0 commit comments