Skip to content

Commit 0324ab0

Browse files
committed
Remove no-op methods
1 parent b137e6a commit 0324ab0

File tree

2 files changed

+45
-90
lines changed

2 files changed

+45
-90
lines changed

temporalio/worker/_command_aware_visitor.py

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from temporalio.bridge._visitor import PayloadVisitor, VisitorFunctions
1010
from temporalio.bridge.proto.workflow_activation import workflow_activation_pb2
1111
from temporalio.bridge.proto.workflow_activation.workflow_activation_pb2 import (
12-
FireTimer,
1312
ResolveActivity,
1413
ResolveChildWorkflowExecution,
1514
ResolveChildWorkflowExecutionStart,
@@ -20,18 +19,11 @@
2019
)
2120
from temporalio.bridge.proto.workflow_commands import workflow_commands_pb2
2221
from temporalio.bridge.proto.workflow_commands.workflow_commands_pb2 import (
23-
CancelSignalWorkflow,
24-
CancelTimer,
25-
RequestCancelActivity,
26-
RequestCancelExternalWorkflowExecution,
27-
RequestCancelLocalActivity,
28-
RequestCancelNexusOperation,
2922
ScheduleActivity,
3023
ScheduleLocalActivity,
3124
ScheduleNexusOperation,
3225
SignalExternalWorkflowExecution,
3326
StartChildWorkflowExecution,
34-
StartTimer,
3527
)
3628

3729

@@ -51,11 +43,11 @@ class CommandInfo:
5143
class CommandAwarePayloadVisitor(PayloadVisitor):
5244
"""Payload visitor that sets command context during traversal.
5345
54-
Override methods are explicitly defined for all workflow commands and
55-
activation jobs that have a 'seq' field.
46+
Override methods are explicitly defined for workflow commands and
47+
activation jobs that have both a 'seq' field and payloads to visit.
5648
"""
5749

58-
# Workflow commands
50+
# Workflow commands with payloads
5951
async def _visit_coresdk_workflow_commands_ScheduleActivity(
6052
self, fs: VisitorFunctions, o: ScheduleActivity
6153
) -> None:
@@ -88,72 +80,13 @@ async def _visit_coresdk_workflow_commands_SignalExternalWorkflowExecution(
8880
fs, o
8981
)
9082

91-
async def _visit_coresdk_workflow_commands_RequestCancelExternalWorkflowExecution(
92-
self, fs: VisitorFunctions, o: RequestCancelExternalWorkflowExecution
93-
) -> None:
94-
with current_command(
95-
CommandType.COMMAND_TYPE_REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION, o.seq
96-
):
97-
# Note: Base class doesn't have this visitor (no payloads to visit)
98-
pass
99-
10083
async def _visit_coresdk_workflow_commands_ScheduleNexusOperation(
10184
self, fs: VisitorFunctions, o: ScheduleNexusOperation
10285
) -> None:
10386
with current_command(CommandType.COMMAND_TYPE_SCHEDULE_NEXUS_OPERATION, o.seq):
10487
await super()._visit_coresdk_workflow_commands_ScheduleNexusOperation(fs, o)
10588

106-
async def _visit_coresdk_workflow_commands_RequestCancelNexusOperation(
107-
self, fs: VisitorFunctions, o: RequestCancelNexusOperation
108-
) -> None:
109-
with current_command(
110-
CommandType.COMMAND_TYPE_REQUEST_CANCEL_NEXUS_OPERATION, o.seq
111-
):
112-
# Note: Base class doesn't have this visitor (no payloads to visit)
113-
pass
114-
115-
async def _visit_coresdk_workflow_commands_StartTimer(
116-
self, fs: VisitorFunctions, o: StartTimer
117-
) -> None:
118-
with current_command(CommandType.COMMAND_TYPE_START_TIMER, o.seq):
119-
# Note: Base class doesn't have this visitor (no payloads to visit)
120-
pass
121-
122-
async def _visit_coresdk_workflow_commands_CancelTimer(
123-
self, fs: VisitorFunctions, o: CancelTimer
124-
) -> None:
125-
with current_command(CommandType.COMMAND_TYPE_CANCEL_TIMER, o.seq):
126-
# Note: Base class doesn't have this visitor (no payloads to visit)
127-
pass
128-
129-
async def _visit_coresdk_workflow_commands_RequestCancelActivity(
130-
self, fs: VisitorFunctions, o: RequestCancelActivity
131-
) -> None:
132-
with current_command(
133-
CommandType.COMMAND_TYPE_REQUEST_CANCEL_ACTIVITY_TASK, o.seq
134-
):
135-
# Note: Base class doesn't have this visitor (no payloads to visit)
136-
pass
137-
138-
async def _visit_coresdk_workflow_commands_RequestCancelLocalActivity(
139-
self, fs: VisitorFunctions, o: RequestCancelLocalActivity
140-
) -> None:
141-
with current_command(
142-
CommandType.COMMAND_TYPE_REQUEST_CANCEL_ACTIVITY_TASK, o.seq
143-
):
144-
# Note: Base class doesn't have this visitor (no payloads to visit)
145-
pass
146-
147-
async def _visit_coresdk_workflow_commands_CancelSignalWorkflow(
148-
self, fs: VisitorFunctions, o: CancelSignalWorkflow
149-
) -> None:
150-
# CancelSignalWorkflow has seq but no server command type
151-
# (it's an internal SDK command). Set context to None.
152-
with current_command(None, o.seq): # type: ignore
153-
# Note: Base class doesn't have this visitor (no payloads to visit)
154-
pass
155-
156-
# Workflow activation jobs
89+
# Workflow activation jobs with payloads
15790
async def _visit_coresdk_workflow_activation_ResolveActivity(
15891
self, fs: VisitorFunctions, o: ResolveActivity
15992
) -> None:
@@ -216,13 +149,6 @@ async def _visit_coresdk_workflow_activation_ResolveNexusOperation(
216149
fs, o
217150
)
218151

219-
async def _visit_coresdk_workflow_activation_FireTimer(
220-
self, fs: VisitorFunctions, o: FireTimer
221-
) -> None:
222-
with current_command(CommandType.COMMAND_TYPE_START_TIMER, o.seq):
223-
# Note: Base class doesn't have this visitor (no payloads to visit)
224-
pass
225-
226152

227153
def _get_workflow_command_protos_with_seq() -> Iterator[Type[Any]]:
228154
"""Get concrete classes of all workflow command protos with a seq field."""
Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,75 @@
1-
"""Test that CommandAwarePayloadVisitor handles all commands with seq fields."""
1+
"""Test that CommandAwarePayloadVisitor handles all commands with seq fields that have payloads."""
22

3+
from temporalio.bridge._visitor import PayloadVisitor
34
from temporalio.worker._command_aware_visitor import (
45
CommandAwarePayloadVisitor,
56
_get_workflow_activation_job_protos_with_seq,
67
_get_workflow_command_protos_with_seq,
78
)
89

910

10-
def test_command_aware_visitor_has_methods_for_all_seq_protos():
11-
"""Verify CommandAwarePayloadVisitor has methods for all protos with seq fields."""
12-
visitor = CommandAwarePayloadVisitor()
11+
def test_command_aware_visitor_has_methods_for_all_seq_protos_with_payloads():
12+
"""Verify CommandAwarePayloadVisitor has methods for all protos with seq fields that have payloads.
1313
14-
# Check all workflow commands with seq have corresponding methods
14+
We only override methods when the base class has a visitor method (i.e., there are payloads to visit).
15+
Commands without payloads don't need overrides since there's nothing to visit.
16+
"""
17+
visitor = CommandAwarePayloadVisitor()
1518

19+
# Find all protos with seq
1620
command_protos = list(_get_workflow_command_protos_with_seq())
1721
job_protos = list(_get_workflow_activation_job_protos_with_seq())
1822
assert command_protos, "Should find workflow commands with seq"
1923
assert job_protos, "Should find workflow activation jobs with seq"
2024

25+
# Check workflow commands - only ones with payloads need overrides
2126
commands_missing = []
27+
commands_with_payloads = []
2228
for proto_class in command_protos:
2329
method_name = f"_visit_coresdk_workflow_commands_{proto_class.__name__}"
24-
if not hasattr(visitor, method_name):
25-
commands_missing.append(proto_class.__name__)
30+
# Only check if base class has this visitor (meaning there are payloads)
31+
if hasattr(PayloadVisitor, method_name):
32+
commands_with_payloads.append(proto_class.__name__)
33+
# Check if CommandAwarePayloadVisitor has its own override (not just inherited)
34+
if method_name not in CommandAwarePayloadVisitor.__dict__:
35+
commands_missing.append(proto_class.__name__)
2636

27-
# Check all workflow activation jobs with seq have corresponding methods
37+
# Check workflow activation jobs - only ones with payloads need overrides
2838
jobs_missing = []
39+
jobs_with_payloads = []
2940
for proto_class in job_protos:
3041
method_name = f"_visit_coresdk_workflow_activation_{proto_class.__name__}"
31-
if not hasattr(visitor, method_name):
32-
jobs_missing.append(proto_class.__name__)
42+
# Only check if base class has this visitor (meaning there are payloads)
43+
if hasattr(PayloadVisitor, method_name):
44+
jobs_with_payloads.append(proto_class.__name__)
45+
# Check if CommandAwarePayloadVisitor has its own override (not just inherited)
46+
if method_name not in CommandAwarePayloadVisitor.__dict__:
47+
jobs_missing.append(proto_class.__name__)
3348

3449
errors = []
3550
if commands_missing:
3651
errors.append(
37-
f"Missing visitor methods for commands with seq: {commands_missing}\n"
52+
f"Missing visitor methods for commands with seq and payloads: {commands_missing}\n"
3853
f"Add methods to CommandAwarePayloadVisitor for these commands."
3954
)
4055
if jobs_missing:
4156
errors.append(
42-
f"Missing visitor methods for activation jobs with seq: {jobs_missing}\n"
57+
f"Missing visitor methods for activation jobs with seq and payloads: {jobs_missing}\n"
4358
f"Add methods to CommandAwarePayloadVisitor for these jobs."
4459
)
4560

4661
assert not errors, "\n".join(errors)
62+
63+
# Verify we found the expected commands/jobs with payloads
64+
assert len(commands_with_payloads) > 0, "Should find commands with payloads"
65+
assert len(jobs_with_payloads) > 0, "Should find activation jobs with payloads"
66+
67+
# Sanity check: we should have fewer overrides than total protos with seq
68+
# (because some don't have payloads)
69+
assert len(commands_with_payloads) < len(
70+
command_protos
71+
), "Should have some commands without payloads"
72+
# All activation jobs except FireTimer have payloads
73+
assert (
74+
len(jobs_with_payloads) == len(job_protos) - 1
75+
), "Should have exactly one activation job without payloads (FireTimer)"

0 commit comments

Comments
 (0)