@@ -170,22 +170,18 @@ def activate(
170170 raise NotImplementedError
171171
172172 @abstractmethod
173- def get_payload_codec_with_context (
173+ def get_serialization_context (
174174 self ,
175- base_payload_codec : temporalio .converter .PayloadCodec ,
176- workflow_context_payload_codec : temporalio .converter .PayloadCodec ,
177175 command_info : Optional [temporalio .bridge ._visitor .CommandInfo ],
178- ) -> temporalio .converter .PayloadCodec :
179- """Return a payload codec with appropriate serialization context.
176+ ) -> Optional [ temporalio .converter .SerializationContext ] :
177+ """Return appropriate serialization context.
180178
181179 Args:
182- base_payload_codec: The base payload codec to apply context to.
183- workflow_context_payload_codec: A payload codec that already has workflow context set.
184180 command_info: Optional information identifying the associated command. If set, the payload
185181 codec will have serialization context set appropriately for that command.
186182
187183 Returns:
188- The payload codec .
184+ The serialization context, or None if no context should be set .
189185 """
190186 raise NotImplementedError
191187
@@ -2116,22 +2112,18 @@ def _converters_with_context(
21162112 failure_converter = failure_converter .with_context (context )
21172113 return payload_converter , failure_converter
21182114
2119- def get_payload_codec_with_context (
2115+ def get_serialization_context (
21202116 self ,
2121- base_payload_codec : temporalio .converter .PayloadCodec ,
2122- workflow_context_payload_codec : temporalio .converter .PayloadCodec ,
21232117 command_info : Optional [temporalio .bridge ._visitor .CommandInfo ],
2124- ) -> temporalio .converter .PayloadCodec :
2125- if not isinstance (
2126- base_payload_codec ,
2127- temporalio .converter .WithSerializationContext ,
2128- ):
2129- return base_payload_codec
2130-
2118+ ) -> Optional [temporalio .converter .SerializationContext ]:
2119+ workflow_context = temporalio .converter .WorkflowSerializationContext (
2120+ namespace = self ._info .namespace ,
2121+ workflow_id = self ._info .workflow_id ,
2122+ )
21312123 if command_info is None :
21322124 # Use payload codec with workflow context by default (i.e. for payloads not associated
21332125 # with a pending command)
2134- return workflow_context_payload_codec
2126+ return workflow_context
21352127
21362128 if (
21372129 command_info .command_type
@@ -2140,22 +2132,18 @@ def get_payload_codec_with_context(
21402132 ):
21412133 # Use the activity's context
21422134 activity_handle = self ._pending_activities [command_info .command_seq ]
2143- return base_payload_codec .with_context (
2144- temporalio .converter .ActivitySerializationContext (
2145- namespace = self ._info .namespace ,
2146- workflow_id = self ._info .workflow_id ,
2147- workflow_type = self ._info .workflow_type ,
2148- activity_type = activity_handle ._input .activity ,
2149- activity_task_queue = (
2150- activity_handle ._input .task_queue
2151- if isinstance (activity_handle ._input , StartActivityInput )
2152- and activity_handle ._input .task_queue
2153- else self ._info .task_queue
2154- ),
2155- is_local = isinstance (
2156- activity_handle ._input , StartLocalActivityInput
2157- ),
2158- )
2135+ return temporalio .converter .ActivitySerializationContext (
2136+ namespace = self ._info .namespace ,
2137+ workflow_id = self ._info .workflow_id ,
2138+ workflow_type = self ._info .workflow_type ,
2139+ activity_type = activity_handle ._input .activity ,
2140+ activity_task_queue = (
2141+ activity_handle ._input .task_queue
2142+ if isinstance (activity_handle ._input , StartActivityInput )
2143+ and activity_handle ._input .task_queue
2144+ else self ._info .task_queue
2145+ ),
2146+ is_local = isinstance (activity_handle ._input , StartLocalActivityInput ),
21592147 )
21602148
21612149 elif (
@@ -2165,11 +2153,9 @@ def get_payload_codec_with_context(
21652153 ):
21662154 # Use the child workflow's context
21672155 child_wf_handle = self ._pending_child_workflows [command_info .command_seq ]
2168- return base_payload_codec .with_context (
2169- temporalio .converter .WorkflowSerializationContext (
2170- namespace = self ._info .namespace ,
2171- workflow_id = child_wf_handle ._input .id ,
2172- )
2156+ return temporalio .converter .WorkflowSerializationContext (
2157+ namespace = self ._info .namespace ,
2158+ workflow_id = child_wf_handle ._input .id ,
21732159 )
21742160
21752161 elif (
@@ -2181,11 +2167,9 @@ def get_payload_codec_with_context(
21812167 _ , target_workflow_id = self ._pending_external_signals [
21822168 command_info .command_seq
21832169 ]
2184- return base_payload_codec .with_context (
2185- temporalio .converter .WorkflowSerializationContext (
2186- namespace = self ._info .namespace ,
2187- workflow_id = target_workflow_id ,
2188- )
2170+ return temporalio .converter .WorkflowSerializationContext (
2171+ namespace = self ._info .namespace ,
2172+ workflow_id = target_workflow_id ,
21892173 )
21902174
21912175 elif (
@@ -2196,11 +2180,11 @@ def get_payload_codec_with_context(
21962180 # Use empty context for nexus operations: users will never want to encrypt using a
21972181 # key derived from caller workflow context because the caller workflow context is
21982182 # not available on the handler side for decryption.
2199- return base_payload_codec
2183+ return None
22002184
22012185 else :
22022186 # Use payload codec with workflow context for all other payloads
2203- return workflow_context_payload_codec
2187+ return workflow_context
22042188
22052189 def _instantiate_workflow_object (self ) -> Any :
22062190 if not self ._workflow_input :
0 commit comments