Skip to content

Commit 43660f4

Browse files
committed
Respond to upstream: retryable_override instead of enum
1 parent c967aa5 commit 43660f4

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

temporalio/converter.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -945,9 +945,9 @@ def _nexus_handler_error_to_failure(
945945
failure.nexus_handler_failure_info.type = error.type.name
946946
failure.nexus_handler_failure_info.retry_behavior = temporalio.api.enums.v1.NexusHandlerErrorRetryBehavior.ValueType(
947947
temporalio.api.enums.v1.NexusHandlerErrorRetryBehavior.NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_RETRYABLE
948-
if error.retry_behavior == nexusrpc.HandlerErrorRetryBehavior.RETRYABLE
948+
if error.retryable_override is True
949949
else temporalio.api.enums.v1.NexusHandlerErrorRetryBehavior.NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_NON_RETRYABLE
950-
if error.retry_behavior == nexusrpc.HandlerErrorRetryBehavior.NON_RETRYABLE
950+
if error.retryable_override is False
951951
else temporalio.api.enums.v1.NexusHandlerErrorRetryBehavior.NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_UNSPECIFIED
952952
)
953953

@@ -1054,13 +1054,13 @@ def from_failure(
10541054
f"Unknown Nexus HandlerErrorType: {nexus_handler_failure_info.type}"
10551055
)
10561056
_type = nexusrpc.HandlerErrorType.INTERNAL
1057-
retry_behavior = (
1058-
nexusrpc.HandlerErrorRetryBehavior.RETRYABLE
1057+
retryable_override = (
1058+
True
10591059
if (
10601060
nexus_handler_failure_info.retry_behavior
10611061
== temporalio.api.enums.v1.NexusHandlerErrorRetryBehavior.NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_RETRYABLE
10621062
)
1063-
else nexusrpc.HandlerErrorRetryBehavior.NON_RETRYABLE
1063+
else False
10641064
if (
10651065
nexus_handler_failure_info.retry_behavior
10661066
== temporalio.api.enums.v1.NexusHandlerErrorRetryBehavior.NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_NON_RETRYABLE
@@ -1070,7 +1070,7 @@ def from_failure(
10701070
err = nexusrpc.HandlerError(
10711071
failure.message or "Nexus handler error",
10721072
type=_type,
1073-
retry_behavior=retry_behavior,
1073+
retryable_override=retryable_override,
10741074
)
10751075
elif failure.HasField("nexus_operation_execution_failure_info"):
10761076
nexus_op_failure_info = failure.nexus_operation_execution_failure_info

temporalio/worker/_nexus.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,9 @@ async def _handler_error_to_proto(
399399
"""
400400
retry_behavior = (
401401
temporalio.api.enums.v1.NexusHandlerErrorRetryBehavior.NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_RETRYABLE
402-
if (
403-
handler_error.retry_behavior
404-
== nexusrpc.HandlerErrorRetryBehavior.RETRYABLE
405-
)
402+
if handler_error.retryable_override is True
406403
else temporalio.api.enums.v1.NexusHandlerErrorRetryBehavior.NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_NON_RETRYABLE
407-
if (
408-
handler_error.retry_behavior
409-
== nexusrpc.HandlerErrorRetryBehavior.NON_RETRYABLE
410-
)
404+
if handler_error.retryable_override is False
411405
else temporalio.api.enums.v1.NexusHandlerErrorRetryBehavior.NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_UNSPECIFIED
412406
)
413407
return temporalio.api.nexus.v1.HandlerError(
@@ -442,7 +436,7 @@ async def deserialize(
442436
raise nexusrpc.HandlerError(
443437
"Data converter failed to decode Nexus operation input",
444438
type=nexusrpc.HandlerErrorType.BAD_REQUEST,
445-
retry_behavior=nexusrpc.HandlerErrorRetryBehavior.NON_RETRYABLE,
439+
retryable_override=False,
446440
) from err
447441

448442

@@ -457,11 +451,7 @@ def _exception_to_handler_error(err: BaseException) -> nexusrpc.HandlerError:
457451
# TODO(nexus-preview): confirm what we want as message here
458452
err.message,
459453
type=nexusrpc.HandlerErrorType.INTERNAL,
460-
retry_behavior=(
461-
nexusrpc.HandlerErrorRetryBehavior.NON_RETRYABLE
462-
if err.non_retryable
463-
else nexusrpc.HandlerErrorRetryBehavior.RETRYABLE
464-
),
454+
retryable_override=not err.non_retryable,
465455
)
466456
elif isinstance(err, RPCError):
467457
if err.status == RPCStatusCode.INVALID_ARGUMENT:
@@ -477,7 +467,7 @@ def _exception_to_handler_error(err: BaseException) -> nexusrpc.HandlerError:
477467
handler_err = nexusrpc.HandlerError(
478468
err.message,
479469
type=nexusrpc.HandlerErrorType.INTERNAL,
480-
retry_behavior=nexusrpc.HandlerErrorRetryBehavior.NON_RETRYABLE,
470+
retryable_override=False,
481471
)
482472
elif err.status in [RPCStatusCode.ABORTED, RPCStatusCode.UNAVAILABLE]:
483473
handler_err = nexusrpc.HandlerError(

tests/nexus/test_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ async def handler_error_internal(
186186
raise HandlerError(
187187
message="deliberate internal handler error",
188188
type=HandlerErrorType.INTERNAL,
189-
retry_behavior=nexusrpc.HandlerErrorRetryBehavior.NON_RETRYABLE,
189+
retryable_override=False,
190190
) from RuntimeError("cause message")
191191

192192
@sync_operation

0 commit comments

Comments
 (0)