|
65 | 65 | from temporalio.service import __version__ |
66 | 66 |
|
67 | 67 | from ..api.failure.v1.message_pb2 import Failure |
| 68 | +from ..converter import ( |
| 69 | + ActivitySerializationContext, |
| 70 | + WithSerializationContext, |
| 71 | + WorkflowSerializationContext, |
| 72 | +) |
68 | 73 | from ._interceptor import ( |
69 | 74 | ContinueAsNewInput, |
70 | 75 | ExecuteWorkflowInput, |
@@ -208,6 +213,19 @@ def __init__(self, det: WorkflowInstanceDetails) -> None: |
208 | 213 | WorkflowInstance.__init__(self) |
209 | 214 | temporalio.workflow._Runtime.__init__(self) |
210 | 215 | self._payload_converter = det.payload_converter_class() |
| 216 | + |
| 217 | + # Apply serialization context to payload converter |
| 218 | + self._payload_converter = ( |
| 219 | + self._payload_converter.with_context( |
| 220 | + WorkflowSerializationContext( |
| 221 | + namespace=det.info.namespace, |
| 222 | + workflow_id=det.info.workflow_id, |
| 223 | + ) |
| 224 | + ) |
| 225 | + if isinstance(self._payload_converter, WithSerializationContext) |
| 226 | + else self._payload_converter |
| 227 | + ) |
| 228 | + |
211 | 229 | self._failure_converter = det.failure_converter_class() |
212 | 230 | self._defn = det.defn |
213 | 231 | self._workflow_input: Optional[ExecuteWorkflowInput] = None |
@@ -1017,6 +1035,7 @@ def _apply_update_random_seed( |
1017 | 1035 | def _make_workflow_input( |
1018 | 1036 | self, init_job: temporalio.bridge.proto.workflow_activation.InitializeWorkflow |
1019 | 1037 | ) -> ExecuteWorkflowInput: |
| 1038 | + print("Making workflow input") |
1020 | 1039 | # Set arg types, using raw values for dynamic |
1021 | 1040 | arg_types = self._defn.arg_types |
1022 | 1041 | if not self._defn.name: |
@@ -1987,6 +2006,7 @@ def _convert_payloads( |
1987 | 2006 | if types and len(types) != len(payloads): |
1988 | 2007 | types = None |
1989 | 2008 | try: |
| 2009 | + print(f"Converting payloads with {self._payload_converter}.") |
1990 | 2010 | return self._payload_converter.from_payloads( |
1991 | 2011 | payloads, |
1992 | 2012 | type_hints=types, |
@@ -2769,9 +2789,27 @@ def _apply_schedule_command( |
2769 | 2789 | temporalio.bridge.proto.activity_result.DoBackoff |
2770 | 2790 | ] = None, |
2771 | 2791 | ) -> None: |
| 2792 | + # Set up serialization context |
| 2793 | + payload_converter = ( |
| 2794 | + self._instance._payload_converter.with_context( |
| 2795 | + ActivitySerializationContext( |
| 2796 | + namespace=self._instance.workflow_info().namespace, |
| 2797 | + workflow_id=self._instance.workflow_info().workflow_id, |
| 2798 | + workflow_type=self._instance.workflow_info().workflow_type, |
| 2799 | + activity_type=self._input.activity, |
| 2800 | + activity_task_queue=self._input.task_queue |
| 2801 | + if isinstance(self._input, StartActivityInput) |
| 2802 | + else None, |
| 2803 | + is_local=isinstance(self._input, StartLocalActivityInput), |
| 2804 | + ) |
| 2805 | + ) |
| 2806 | + if isinstance(self._instance._payload_converter, WithSerializationContext) |
| 2807 | + else self._instance._payload_converter |
| 2808 | + ) |
| 2809 | + |
2772 | 2810 | # Convert arguments before creating command in case it raises error |
2773 | 2811 | payloads = ( |
2774 | | - self._instance._payload_converter.to_payloads(self._input.args) |
| 2812 | + payload_converter.to_payloads(self._input.args) |
2775 | 2813 | if self._input.args |
2776 | 2814 | else None |
2777 | 2815 | ) |
@@ -2807,7 +2845,7 @@ def _apply_schedule_command( |
2807 | 2845 | self._input.retry_policy.apply_to_proto(v.retry_policy) |
2808 | 2846 | if self._input.summary: |
2809 | 2847 | command.user_metadata.summary.CopyFrom( |
2810 | | - self._instance._payload_converter.to_payload(self._input.summary) |
| 2848 | + payload_converter.to_payload(self._input.summary) |
2811 | 2849 | ) |
2812 | 2850 | v.cancellation_type = cast( |
2813 | 2851 | temporalio.bridge.proto.workflow_commands.ActivityCancellationType.ValueType, |
@@ -2919,9 +2957,21 @@ def _resolve_failure(self, err: BaseException) -> None: |
2919 | 2957 | self._result_fut.set_result(None) |
2920 | 2958 |
|
2921 | 2959 | def _apply_start_command(self) -> None: |
| 2960 | + # Set up serialization context |
| 2961 | + payload_converter = ( |
| 2962 | + self._instance._payload_converter.with_context( |
| 2963 | + WorkflowSerializationContext( |
| 2964 | + namespace=self._instance.workflow_info().namespace, |
| 2965 | + workflow_id=self._instance.workflow_info().workflow_id, |
| 2966 | + ) |
| 2967 | + ) |
| 2968 | + if isinstance(self._instance._payload_converter, WithSerializationContext) |
| 2969 | + else self._instance._payload_converter |
| 2970 | + ) |
| 2971 | + |
2922 | 2972 | # Convert arguments before creating command in case it raises error |
2923 | 2973 | payloads = ( |
2924 | | - self._instance._payload_converter.to_payloads(self._input.args) |
| 2974 | + payload_converter.to_payloads(self._input.args) |
2925 | 2975 | if self._input.args |
2926 | 2976 | else None |
2927 | 2977 | ) |
@@ -2956,9 +3006,7 @@ def _apply_start_command(self) -> None: |
2956 | 3006 | temporalio.common._apply_headers(self._input.headers, v.headers) |
2957 | 3007 | if self._input.memo: |
2958 | 3008 | for k, val in self._input.memo.items(): |
2959 | | - v.memo[k].CopyFrom( |
2960 | | - self._instance._payload_converter.to_payloads([val])[0] |
2961 | | - ) |
| 3009 | + v.memo[k].CopyFrom(payload_converter.to_payloads([val])[0]) |
2962 | 3010 | if self._input.search_attributes: |
2963 | 3011 | _encode_search_attributes( |
2964 | 3012 | self._input.search_attributes, v.search_attributes |
@@ -3126,15 +3174,27 @@ def __init__( |
3126 | 3174 | self._input = input |
3127 | 3175 |
|
3128 | 3176 | def _apply_command(self) -> None: |
| 3177 | + # Set up serialization context |
| 3178 | + payload_converter = ( |
| 3179 | + self._instance._payload_converter.with_context( |
| 3180 | + WorkflowSerializationContext( |
| 3181 | + namespace=self._instance.workflow_info().namespace, |
| 3182 | + workflow_id=self._instance.workflow_info().workflow_id, |
| 3183 | + ) |
| 3184 | + ) |
| 3185 | + if isinstance(self._instance._payload_converter, WithSerializationContext) |
| 3186 | + else self._instance._payload_converter |
| 3187 | + ) |
| 3188 | + |
3129 | 3189 | # Convert arguments before creating command in case it raises error |
3130 | 3190 | payloads = ( |
3131 | | - self._instance._payload_converter.to_payloads(self._input.args) |
| 3191 | + payload_converter.to_payloads(self._input.args) |
3132 | 3192 | if self._input.args |
3133 | 3193 | else None |
3134 | 3194 | ) |
3135 | 3195 | memo_payloads = ( |
3136 | 3196 | { |
3137 | | - k: self._instance._payload_converter.to_payloads([val])[0] |
| 3197 | + k: payload_converter.to_payloads([val])[0] |
3138 | 3198 | for k, val in self._input.memo.items() |
3139 | 3199 | } |
3140 | 3200 | if self._input.memo |
|
0 commit comments