Skip to content

Commit b2d12f4

Browse files
committed
Workaround union serialization issues
1 parent 0068b91 commit b2d12f4

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

tests/test_serialization_context.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
class TraceItem:
3131
context_type: Literal["workflow", "activity"]
3232
method: Literal["to_payload", "from_payload"]
33-
context: WorkflowSerializationContext | ActivitySerializationContext
33+
context: dict[str, Any]
3434
in_workflow: bool
3535
caller_location: list[str] = field(default_factory=list)
3636

@@ -93,7 +93,7 @@ def to_payload(self, value: Any) -> Optional[Payload]:
9393
context_type="workflow",
9494
in_workflow=workflow.in_workflow(),
9595
method="to_payload",
96-
context=self.context,
96+
context=dataclasses.asdict(self.context),
9797
caller_location=get_caller_location(),
9898
)
9999
)
@@ -103,7 +103,7 @@ def to_payload(self, value: Any) -> Optional[Payload]:
103103
context_type="activity",
104104
in_workflow=workflow.in_workflow(),
105105
method="to_payload",
106-
context=self.context,
106+
context=dataclasses.asdict(self.context),
107107
caller_location=get_caller_location(),
108108
)
109109
)
@@ -125,7 +125,7 @@ def from_payload(self, payload: Payload, type_hint: Optional[Type] = None) -> An
125125
context_type="workflow",
126126
in_workflow=workflow.in_workflow(),
127127
method="from_payload",
128-
context=self.context,
128+
context=dataclasses.asdict(self.context),
129129
caller_location=get_caller_location(),
130130
)
131131
)
@@ -135,7 +135,7 @@ def from_payload(self, payload: Payload, type_hint: Optional[Type] = None) -> An
135135
context_type="activity",
136136
in_workflow=workflow.in_workflow(),
137137
method="from_payload",
138-
context=self.context,
138+
context=dataclasses.asdict(self.context),
139139
caller_location=get_caller_location(),
140140
)
141141
)
@@ -183,17 +183,21 @@ async def test_workflow_payload_conversion_can_be_given_access_to_serialization_
183183
task_queue=task_queue,
184184
)
185185

186-
workflow_context = WorkflowSerializationContext(
187-
namespace="default",
188-
workflow_id=workflow_id,
186+
workflow_context = dataclasses.asdict(
187+
WorkflowSerializationContext(
188+
namespace="default",
189+
workflow_id=workflow_id,
190+
)
189191
)
190-
activity_context = ActivitySerializationContext(
191-
namespace="default",
192-
workflow_id=workflow_id,
193-
workflow_type="SerializationContextTestWorkflow",
194-
activity_type="passthrough_activity",
195-
activity_task_queue=task_queue,
196-
is_local=False,
192+
activity_context = dataclasses.asdict(
193+
ActivitySerializationContext(
194+
namespace="default",
195+
workflow_id=workflow_id,
196+
workflow_type="SerializationContextTestWorkflow",
197+
activity_type="passthrough_activity",
198+
activity_task_queue=task_queue,
199+
is_local=False,
200+
)
197201
)
198202
if True:
199203
assert_trace(
@@ -230,10 +234,10 @@ async def test_workflow_payload_conversion_can_be_given_access_to_serialization_
230234
context=activity_context,
231235
),
232236
TraceItem(
233-
context_type="workflow",
237+
context_type="activity",
234238
in_workflow=False,
235239
method="from_payload",
236-
context=workflow_context,
240+
context=activity_context,
237241
),
238242
TraceItem(
239243
context_type="workflow",

0 commit comments

Comments
 (0)