@@ -167,6 +167,20 @@ def activate(
167167 """
168168 raise NotImplementedError
169169
170+ @abstractmethod
171+ def get_pending_command_serialization_context (
172+ self , command_seq : int
173+ ) -> Optional [temporalio .converter .SerializationContext ]:
174+ """Return the serialization context for a pending command.
175+
176+ Args:
177+ command_seq: The sequence number of the command.
178+
179+ Returns:
180+ The serialization context for the command, or None if not found.
181+ """
182+ raise NotImplementedError
183+
170184 def get_thread_id (self ) -> Optional [int ]:
171185 """Return the thread identifier that this workflow is running on.
172186
@@ -225,6 +239,7 @@ def __init__(self, det: WorkflowInstanceDetails) -> None:
225239 self ._context_free_failure_converter ,
226240 )
227241 )
242+ self ._payload_codec = det .data_converter .payload_codec
228243
229244 self ._extern_functions = det .extern_functions
230245 self ._disable_eager_activity_execution = det .disable_eager_activity_execution
@@ -2089,6 +2104,45 @@ def _converters_with_context(
20892104 failure_converter = failure_converter .with_context (context )
20902105 return payload_converter , failure_converter
20912106
2107+ def get_pending_command_serialization_context (
2108+ self , command_seq : int
2109+ ) -> Optional [temporalio .converter .SerializationContext ]:
2110+ if isinstance (
2111+ self ._payload_codec , temporalio .converter .WithSerializationContext
2112+ ):
2113+ if command_seq in self ._pending_activities :
2114+ handle = self ._pending_activities [command_seq ]
2115+ return temporalio .converter .ActivitySerializationContext (
2116+ namespace = self ._info .namespace ,
2117+ workflow_id = self ._info .workflow_id ,
2118+ workflow_type = self ._info .workflow_type ,
2119+ activity_type = handle ._input .activity ,
2120+ activity_task_queue = (
2121+ handle ._input .task_queue or self ._info .task_queue
2122+ if isinstance (handle ._input , StartActivityInput )
2123+ else self ._info .task_queue
2124+ ),
2125+ is_local = isinstance (handle ._input , StartLocalActivityInput ),
2126+ )
2127+
2128+ elif command_seq in self ._pending_child_workflows :
2129+ handle = self ._pending_child_workflows [command_seq ]
2130+ return temporalio .converter .WorkflowSerializationContext (
2131+ namespace = self ._info .namespace ,
2132+ workflow_id = handle ._input .id ,
2133+ )
2134+
2135+ elif command_seq in self ._pending_external_signals :
2136+ _ , workflow_id = self ._pending_external_signals [command_seq ]
2137+ return temporalio .converter .WorkflowSerializationContext (
2138+ namespace = self ._info .namespace ,
2139+ workflow_id = workflow_id ,
2140+ )
2141+
2142+ elif command_seq in self ._pending_nexus_operations :
2143+ # We don't set any context for nexus operations
2144+ pass
2145+
20922146 def _instantiate_workflow_object (self ) -> Any :
20932147 if not self ._workflow_input :
20942148 raise RuntimeError ("Expected workflow input. This is a Python SDK bug." )
0 commit comments