Skip to content

Commit 3ab946d

Browse files
committed
Address PR feedback
1 parent b182df4 commit 3ab946d

4 files changed

Lines changed: 19 additions & 17 deletions

File tree

temporalio/nexus/_link_conversion.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ def temporal_link_to_nexus_link(
9999
100100
Returns None when the Temporal link variant is missing.
101101
"""
102-
match temporal_link.WhichOneof("variant"):
102+
variant = temporal_link.WhichOneof("variant")
103+
match variant:
103104
case "workflow_event":
104105
return workflow_event_to_nexus_link(temporal_link.workflow_event)
105106

@@ -111,7 +112,7 @@ def temporal_link_to_nexus_link(
111112

112113
case "batch_job" | "workflow":
113114
raise NotImplementedError(
114-
"only workflow_event, activity and nexus_operation links are supported"
115+
f"only workflow_event, activity and nexus_operation links are supported, got {variant}"
115116
)
116117

117118
case None:

temporalio/nexus/_operation_handlers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ async def cancel(self, ctx: CancelOperationContext, token: str) -> None:
208208
if not operation_token.workflow_id:
209209
raise HandlerError(
210210
"Invalid workflow run operation token: missing workflow ID",
211-
type=HandlerErrorType.NOT_FOUND,
211+
type=HandlerErrorType.INTERNAL,
212+
retryable_override=False,
212213
)
213214
wf_cancel_opts = CancelWorkflowRunOptions(
214215
workflow_id=operation_token.workflow_id
@@ -219,12 +220,14 @@ async def cancel(self, ctx: CancelOperationContext, token: str) -> None:
219220
if not operation_token.activity_id:
220221
raise HandlerError(
221222
"Invalid activity operation token: missing activity ID",
222-
type=HandlerErrorType.NOT_FOUND,
223+
type=HandlerErrorType.INTERNAL,
224+
retryable_override=False,
223225
)
224226
if not operation_token.run_id:
225227
raise HandlerError(
226228
"Invalid activity operation token: missing run ID",
227-
type=HandlerErrorType.NOT_FOUND,
229+
type=HandlerErrorType.INTERNAL,
230+
retryable_override=False,
228231
)
229232
activity_cancel_opts = CancelActivityOptions(
230233
activity_id=operation_token.activity_id,

temporalio/nexus/_token.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,16 @@ def decode(cls, token: str) -> Self:
113113
f"invalid token: expected run id to be a string, got {type(run_id)}"
114114
)
115115

116-
if token_type == OperationTokenType.ACTIVITY and not activity_id:
117-
raise TypeError(
118-
"invalid token: expected non-empty activity id for token type `ACTIVITY`"
119-
)
116+
if token_type == OperationTokenType.ACTIVITY:
117+
if not activity_id:
118+
raise TypeError(
119+
"invalid token: expected non-empty activity id for token type `ACTIVITY`"
120+
)
121+
122+
if not run_id:
123+
raise TypeError(
124+
"invalid token: expected non-empty run id for token type `ACTIVITY`"
125+
)
120126

121127
namespace = token_details.get("ns")
122128
if not isinstance(namespace, str):

tests/nexus/test_operation_token.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,6 @@ def test_workflow_handle_to_from_token_round_trip():
124124
run_id="run-id",
125125
),
126126
),
127-
(
128-
_encode_json_token({"t": 2, "ns": "", "aid": "activity-id"}),
129-
OperationToken(
130-
type=OperationTokenType.ACTIVITY,
131-
namespace="",
132-
activity_id="activity-id",
133-
),
134-
),
135127
(
136128
_encode_json_token(
137129
{"t": 2, "ns": "", "aid": "activity-id", "rid": "run-id"}

0 commit comments

Comments
 (0)