Skip to content

Commit d28ae5b

Browse files
committed
Eliminate base serialization context class
1 parent 32f5abb commit d28ae5b

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

temporalio/converter.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,7 @@ class SerializationContext(ABC):
9393

9494

9595
@dataclass(frozen=True)
96-
class BaseWorkflowSerializationContext(SerializationContext):
97-
"""Base serialization context shared by workflow and activity serialization contexts."""
98-
99-
namespace: str
100-
workflow_id: Optional[str]
101-
"""Workflow ID."""
102-
103-
104-
@dataclass(frozen=True)
105-
class WorkflowSerializationContext(BaseWorkflowSerializationContext):
96+
class WorkflowSerializationContext(SerializationContext):
10697
"""Serialization context for workflows.
10798
10899
See :py:class:`SerializationContext` for more details.
@@ -115,40 +106,51 @@ class WorkflowSerializationContext(BaseWorkflowSerializationContext):
115106
when the workflow is created by the schedule.
116107
"""
117108

118-
pass
109+
namespace: str
110+
"""Namespace."""
111+
112+
workflow_id: Optional[str]
113+
"""Workflow ID."""
119114

120115

121116
@dataclass(frozen=True)
122-
class ActivitySerializationContext(BaseWorkflowSerializationContext):
117+
class ActivitySerializationContext(SerializationContext):
123118
"""Serialization context for activities.
124119
125120
See :py:class:`SerializationContext` for more details.
126121
127122
Attributes:
128123
namespace: Workflow/activity namespace.
129-
workflow_id: Workflow ID. Note, when creating/describing schedules,
124+
activity_id: Activity ID. Optional if this is an activity started from a workflow.
125+
activity_type: Activity type.
126+
activity_task_queue: Activity task queue.
127+
workflow_id: Workflow ID. Only set if this is an activity started from a workflow. Note, when creating/describing schedules,
130128
this may be the workflow ID prefix as configured, not the final workflow ID when the
131129
workflow is created by the schedule.
132-
workflow_type: Workflow Type.
133-
activity_type: Activity Type.
134-
activity_task_queue: Activity task queue.
135-
is_local: Whether the activity is a local activity.
130+
workflow_type: Workflow Type. Only set if this is an activity started from a workflow.
131+
is_local: Whether the activity is a local activity. False if this is a standalone activity started directly by a client.
136132
"""
137133

138-
workflow_type: Optional[str]
139-
"""Workflow type."""
134+
namespace: str
135+
"""Namespace."""
136+
137+
activity_id: Optional[str]
138+
"""Activity ID. Optional if this is an activity started from a workflow."""
140139

141140
activity_type: str
142141
"""Activity type."""
143142

144-
activity_id: Optional[str]
145-
"""Activity ID."""
146-
147143
activity_task_queue: str
148144
"""Activity task queue."""
149145

146+
workflow_id: Optional[str]
147+
"""Workflow ID if this is an activity started from a workflow."""
148+
149+
workflow_type: Optional[str]
150+
"""Workflow type if this is an activity started from a workflow."""
151+
150152
is_local: bool
151-
"""Whether the activity is a local activity."""
153+
"""Whether the activity is a local activity started from a workflow."""
152154

153155

154156
class WithSerializationContext(ABC):

tests/test_serialization_context.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ async def test_local_activity_payload_conversion(client: Client):
510510

511511

512512
@workflow.defn
513-
class EventWorkflow:
513+
class WaitForSignalWorkflow:
514514
# Like a global asyncio.Event()
515515

516516
def __init__(self) -> None:
@@ -527,10 +527,11 @@ def signal(self) -> None:
527527

528528
@activity.defn
529529
async def async_activity() -> TraceData:
530+
# Notify test that the activity has started and is ready to be completed manually
530531
await (
531532
activity.client()
532533
.get_workflow_handle("activity-started-wf-id")
533-
.signal(EventWorkflow.signal)
534+
.signal(WaitForSignalWorkflow.signal)
534535
)
535536
activity.raise_complete_async()
536537

@@ -564,7 +565,7 @@ async def test_async_activity_completion_payload_conversion(
564565
task_queue=task_queue,
565566
workflows=[
566567
AsyncActivityCompletionSerializationContextTestWorkflow,
567-
EventWorkflow,
568+
WaitForSignalWorkflow,
568569
],
569570
activities=[async_activity],
570571
workflow_runner=UnsandboxedWorkflowRunner(), # so that we can use isinstance
@@ -584,7 +585,7 @@ async def test_async_activity_completion_payload_conversion(
584585
)
585586

586587
act_started_wf_handle = await client.start_workflow(
587-
EventWorkflow.run,
588+
WaitForSignalWorkflow.run,
588589
id="activity-started-wf-id",
589590
task_queue=task_queue,
590591
)

0 commit comments

Comments
 (0)