dex-python-sdk 1.45.2__tar.gz → 1.45.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/PKG-INFO +1 -1
  2. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/__init__.py +8 -0
  3. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_grpc_errors.py +10 -0
  4. dex_python_sdk-1.45.3/dex/_history_point_mapping.py +156 -0
  5. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_server_protocol.py +13 -1
  6. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/async_client.py +150 -36
  7. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/client.py +161 -36
  8. dex_python_sdk-1.45.3/dex/dexpb/dex_pb2.py +467 -0
  9. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/dexpb/dex_pb2.pyi +112 -4
  10. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/dexpb/dex_pb2_grpc.py +43 -0
  11. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/flow_options.py +338 -0
  12. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/flow_result.py +8 -2
  13. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/runtime_errors.py +65 -0
  14. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/pyproject.toml +1 -1
  15. dex_python_sdk-1.45.2/dex/dexpb/dex_pb2.py +0 -457
  16. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/LEGACY_NOTICES.md +0 -0
  17. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/LICENSE +0 -0
  18. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/README.md +0 -0
  19. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_async_value_hydrator.py +0 -0
  20. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_async_worker_dispatcher.py +0 -0
  21. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_attribute_reads.py +0 -0
  22. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_credential_transport.py +0 -0
  23. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_flow_definition_upload.py +0 -0
  24. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_flow_service_tls.py +0 -0
  25. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_invocation_context.py +0 -0
  26. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_message_size.py +0 -0
  27. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_native.pyi +0 -0
  28. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_pull_worker.py +0 -0
  29. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_task_queue_names.py +0 -0
  30. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_utils.py +0 -0
  31. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_value_hydrator.py +0 -0
  32. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_value_mapper.py +0 -0
  33. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/_worker_dispatcher.py +0 -0
  34. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/action.py +0 -0
  35. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/async_worker.py +0 -0
  36. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/attribute.py +0 -0
  37. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/attribute_match.py +0 -0
  38. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/attribute_values.py +0 -0
  39. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/blob_cache.py +0 -0
  40. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/channel.py +0 -0
  41. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/client_options.py +0 -0
  42. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/codec.py +0 -0
  43. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/condition.py +0 -0
  44. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/context.py +0 -0
  45. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/credential.py +0 -0
  46. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/dexpb/__init__.py +0 -0
  47. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/flow.py +0 -0
  48. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/flow_config.py +0 -0
  49. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/flow_definition.py +0 -0
  50. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/flow_info.py +0 -0
  51. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/flow_service_tls_options.py +0 -0
  52. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/flow_state.py +0 -0
  53. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/join.py +0 -0
  54. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/pull_registration.py +0 -0
  55. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/py.typed +0 -0
  56. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/rpc_invoke_options.py +0 -0
  57. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/step.py +0 -0
  58. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/step_execution.py +0 -0
  59. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/stream.py +0 -0
  60. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/subflow.py +0 -0
  61. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/timer.py +0 -0
  62. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/wait.py +0 -0
  63. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/wait_options.py +0 -0
  64. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/worker.py +0 -0
  65. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/dex/worker_options.py +0 -0
  66. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/Cargo.lock +0 -0
  67. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/Cargo.toml +0 -0
  68. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/Cargo.toml +0 -0
  69. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/LICENSE +0 -0
  70. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/README.md +0 -0
  71. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/src/config.rs +0 -0
  72. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/src/entry.rs +0 -0
  73. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/src/error.rs +0 -0
  74. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/src/format.rs +0 -0
  75. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/src/lib.rs +0 -0
  76. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/src/policy.rs +0 -0
  77. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/src/store.rs +0 -0
  78. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/tests/blob_cache_integration.rs +0 -0
  79. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache-python/Cargo.toml +0 -0
  80. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache-python/LICENSE +0 -0
  81. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache-python/README.md +0 -0
  82. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache-python/src/lib.rs +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dex-python-sdk
3
- Version: 1.45.2
3
+ Version: 1.45.3
4
4
  Requires-Dist: grpcio>=1.83.0
5
5
  Requires-Dist: grpcio-status>=1.83.0
6
6
  Requires-Dist: protobuf>=7.35.1
@@ -78,6 +78,8 @@ from dex.flow_state import (
78
78
  StepMethodPendingReason,
79
79
  )
80
80
  from dex.flow_options import (
81
+ CloneForkFlowOptions,
82
+ CloneForkFlowResult,
81
83
  FlowTimeoutHandlerOptions,
82
84
  FlowTimeoutPolicy,
83
85
  IdReusePolicy,
@@ -85,6 +87,7 @@ from dex.flow_options import (
85
87
  StopFlowOptions,
86
88
  StopType,
87
89
  SubFlowOptions,
90
+ SubFlowResetPolicy,
88
91
  SubFlowReusePolicy,
89
92
  TimeTravelOptions,
90
93
  TimeTravelStepMethod,
@@ -104,6 +107,7 @@ from dex.runtime_errors import (
104
107
  ChannelMessageNotFoundError,
105
108
  ChannelMessagesNotLoadedError,
106
109
  BlobMessageTooLargeError,
110
+ CloneForkFlowUnsupportedError,
107
111
  DexServiceError,
108
112
  ErrorSubStatus,
109
113
  FlowAlreadyStartedError,
@@ -247,6 +251,10 @@ __all__ = [
247
251
  "TimeTravelOptions",
248
252
  "TimeTravelStepMethod",
249
253
  "TimeTravelType",
254
+ "CloneForkFlowOptions",
255
+ "CloneForkFlowResult",
256
+ "CloneForkFlowUnsupportedError",
257
+ "SubFlowResetPolicy",
250
258
  "RetryPolicy",
251
259
  "SearchFlowEntry",
252
260
  "SearchFlowsPage",
@@ -152,6 +152,16 @@ def translate_rpc_error(
152
152
  return DexServiceError(*parameters)
153
153
 
154
154
 
155
+ def translate_clone_fork_flow_error(
156
+ error: grpc.RpcError, source_flow_id: str, flow_id: str
157
+ ) -> DexServiceError:
158
+ """Attribute not-found to the source Flow and every other error to the new Flow."""
159
+ translated = translate_rpc_error(error, "clone_fork_flow", flow_id, "none")
160
+ if translated.sub_status is ErrorSubStatus.FLOW_NOT_EXISTS:
161
+ return translate_rpc_error(error, "clone_fork_flow", source_flow_id, "existing")
162
+ return translated
163
+
164
+
155
165
  def _worker_code(details: pb.ServiceErrorResponse | None) -> grpc.StatusCode | None:
156
166
  if details is None or details.original_worker_error_status == 0:
157
167
  return None
@@ -0,0 +1,156 @@
1
+ # Copyright (c) 2026 Super Durable, Inc.
2
+ #
3
+ # Licensed under the Sustainable Use License 1.0.
4
+ # You may not use this file except in compliance with the License.
5
+ # See the LICENSE file in the repository root.
6
+ #
7
+ # SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
8
+
9
+ from __future__ import annotations
10
+
11
+ from collections.abc import Iterable
12
+ from datetime import datetime
13
+ from uuid import uuid4
14
+
15
+ from dex.dexpb import dex_pb2 as pb
16
+ from dex.flow_options import (
17
+ CloneForkFlowOptions,
18
+ CloneForkFlowResult,
19
+ IdReusePolicy,
20
+ SubFlowResetPolicy,
21
+ TimeTravelOptions,
22
+ TimeTravelStepMethod,
23
+ TimeTravelType,
24
+ _validate_history_point,
25
+ )
26
+
27
+ _RESET_TYPES = {
28
+ TimeTravelType.BEGINNING: pb.FLOW_RESET_TYPE_BEGINNING,
29
+ TimeTravelType.HISTORY_EVENT_TIME: pb.FLOW_RESET_TYPE_HISTORY_EVENT_TIME,
30
+ TimeTravelType.STEP_TYPE: pb.FLOW_RESET_TYPE_STEP_TYPE,
31
+ TimeTravelType.STEP_EXECUTION_ID: pb.FLOW_RESET_TYPE_STEP_EXECUTION_ID,
32
+ TimeTravelType.EVENT_ID: pb.FLOW_RESET_TYPE_EVENT_ID,
33
+ }
34
+
35
+ _CLONE_FORK_POINT_TYPES = {
36
+ TimeTravelType.CURRENT: pb.FLOW_CLONE_FORK_POINT_TYPE_CURRENT,
37
+ TimeTravelType.BEGINNING: pb.FLOW_CLONE_FORK_POINT_TYPE_BEGINNING,
38
+ TimeTravelType.HISTORY_EVENT_TIME: pb.FLOW_CLONE_FORK_POINT_TYPE_HISTORY_EVENT_TIME,
39
+ TimeTravelType.STEP_TYPE: pb.FLOW_CLONE_FORK_POINT_TYPE_STEP_TYPE,
40
+ TimeTravelType.STEP_EXECUTION_ID: pb.FLOW_CLONE_FORK_POINT_TYPE_STEP_EXECUTION_ID,
41
+ TimeTravelType.EVENT_ID: pb.FLOW_CLONE_FORK_POINT_TYPE_EVENT_ID,
42
+ }
43
+
44
+ _STEP_METHODS = {
45
+ TimeTravelStepMethod.WAIT_FOR: pb.FLOW_RESET_STEP_METHOD_WAIT_FOR,
46
+ TimeTravelStepMethod.EXECUTE: pb.FLOW_RESET_STEP_METHOD_EXECUTE,
47
+ }
48
+
49
+ _SUB_FLOW_RESET_POLICIES = {
50
+ SubFlowResetPolicy.DEFAULT: pb.SUB_FLOW_RESET_POLICY_UNSPECIFIED,
51
+ SubFlowResetPolicy.ALWAYS_RESTART: pb.SUB_FLOW_RESET_POLICY_ALWAYS_RESTART,
52
+ SubFlowResetPolicy.ALWAYS_FAIL: pb.SUB_FLOW_RESET_POLICY_ALWAYS_FAIL,
53
+ SubFlowResetPolicy.ALWAYS_REJECT: pb.SUB_FLOW_RESET_POLICY_ALWAYS_REJECT,
54
+ SubFlowResetPolicy.ATTACH_ELSE_RESTART: pb.SUB_FLOW_RESET_POLICY_ATTACH_ELSE_RESTART,
55
+ SubFlowResetPolicy.ATTACH_ELSE_FAIL: pb.SUB_FLOW_RESET_POLICY_ATTACH_ELSE_FAIL,
56
+ SubFlowResetPolicy.ATTACH_ELSE_REJECT: pb.SUB_FLOW_RESET_POLICY_ATTACH_ELSE_REJECT,
57
+ }
58
+
59
+ _ID_REUSE_POLICIES = {
60
+ IdReusePolicy.DEFAULT: pb.ID_REUSE_POLICY_UNSPECIFIED,
61
+ IdReusePolicy.ALLOW_IF_PREVIOUS_FAILED: (
62
+ pb.ID_REUSE_POLICY_ALLOW_IF_PREVIOUS_EXISTS_ABNORMALLY
63
+ ),
64
+ IdReusePolicy.ALLOW_IF_NOT_RUNNING: pb.ID_REUSE_POLICY_ALLOW_IF_NO_RUNNING,
65
+ IdReusePolicy.ALLOW_TERMINATE_IF_RUNNING: (
66
+ pb.ID_REUSE_POLICY_ALLOW_TERMINATE_IF_RUNNING
67
+ ),
68
+ IdReusePolicy.DISALLOW: pb.ID_REUSE_POLICY_DISALLOW_REUSE,
69
+ }
70
+
71
+
72
+ def map_time_travel_request(
73
+ flow_id: str, options: TimeTravelOptions
74
+ ) -> pb.ResetFlowRequest:
75
+ """Map time travel options; only the event ID selector is validated, as before."""
76
+ if options.type is TimeTravelType.CURRENT:
77
+ raise ValueError("time travel type CURRENT is valid only for clone_fork_flow")
78
+ if options.type is TimeTravelType.EVENT_ID or options.event_id is not None:
79
+ _validate_history_point(
80
+ "time travel",
81
+ options.type,
82
+ options.history_event_time,
83
+ options.step_type,
84
+ options.step_execution_id,
85
+ options.step_method,
86
+ options.event_id,
87
+ )
88
+ request = pb.ResetFlowRequest(
89
+ flow_id=flow_id,
90
+ reset_type=_RESET_TYPES[options.type],
91
+ reason=options.reason or "",
92
+ skip_writes_reapply=options.skip_writes_reapply,
93
+ sub_flow_reset_policy=_SUB_FLOW_RESET_POLICIES[options.sub_flow_reset_policy],
94
+ )
95
+ if options.history_event_time is not None:
96
+ request.history_event_time = options.history_event_time.isoformat()
97
+ if options.step_type is not None:
98
+ request.step_type = options.step_type
99
+ if options.step_execution_id is not None:
100
+ request.step_execution_id = options.step_execution_id
101
+ if options.step_method is not None:
102
+ request.step_method = _STEP_METHODS[options.step_method]
103
+ if options.event_id is not None:
104
+ request.event_id = options.event_id
105
+ return request
106
+
107
+
108
+ def map_clone_fork_flow_request(
109
+ source_flow_id: str,
110
+ flow_id: str,
111
+ options: CloneForkFlowOptions,
112
+ flow_config_override: pb.FlowConfig | None,
113
+ attributes: Iterable[pb.AttributeWrite],
114
+ timeout_seconds: int,
115
+ ) -> pb.CloneForkFlowRequest:
116
+ request = pb.CloneForkFlowRequest(
117
+ source_flow_id=source_flow_id,
118
+ source_run_id=options.source_run_id,
119
+ flow_id=flow_id,
120
+ request_id=options.request_id or str(uuid4()),
121
+ id_reuse_policy=_ID_REUSE_POLICIES[options.id_reuse_policy],
122
+ flow_timeout_seconds=timeout_seconds,
123
+ reason=options.reason or "",
124
+ point_type=_CLONE_FORK_POINT_TYPES[options.type],
125
+ history_event_time=_format_history_event_time(options.history_event_time),
126
+ step_type=options.step_type or "",
127
+ step_execution_id=options.step_execution_id or "",
128
+ event_id=options.event_id or 0,
129
+ run_attempt=options.source_run_attempt,
130
+ sub_flow_reset_policy=_SUB_FLOW_RESET_POLICIES[options.sub_flow_reset_policy],
131
+ )
132
+ if options.ignore_already_started:
133
+ request.flow_already_started_options.ignore_already_started_error = True
134
+ if options.step_method is not None:
135
+ request.step_method = _STEP_METHODS[options.step_method]
136
+ if flow_config_override is not None:
137
+ request.flow_config_override.CopyFrom(flow_config_override)
138
+ request.attributes.extend(attributes)
139
+ return request
140
+
141
+
142
+ def clone_fork_flow_result_from_proto(
143
+ response: pb.CloneForkFlowResponse,
144
+ ) -> CloneForkFlowResult:
145
+ if not response.run_id:
146
+ raise RuntimeError("CloneForkFlow response has no run ID")
147
+ return CloneForkFlowResult(
148
+ run_id=response.run_id,
149
+ source_run_id=response.source_run_id,
150
+ source_run_attempt=response.source_run_attempt,
151
+ source_event_id=response.source_event_id,
152
+ )
153
+
154
+
155
+ def _format_history_event_time(history_event_time: datetime | None) -> str:
156
+ return "" if history_event_time is None else history_event_time.isoformat()
@@ -15,11 +15,14 @@ from typing import Iterable
15
15
  import grpc
16
16
 
17
17
  from dex.dexpb import dex_pb2 as pb
18
+ from dex.runtime_errors import CloneForkFlowUnsupportedError
18
19
 
19
20
  MINIMUM_SUPPORTED_SERVER_PROTOCOL_VERSION = 4
20
- MAXIMUM_SUPPORTED_SERVER_PROTOCOL_VERSION = 5
21
+ MAXIMUM_SUPPORTED_SERVER_PROTOCOL_VERSION = 6
21
22
  HARD_DELETE_ATTRIBUTE_PROTOCOL_VERSION = 3
22
23
  NAMED_TASK_QUEUE_PROTOCOL_VERSION = 5
24
+ CLONE_FORK_FLOW_PROTOCOL_VERSION = 6
25
+ CLONE_FORK_FLOW_SERVER_ZD_RELEASE = "server-zd 0.1.33"
23
26
  LAST_SERVER_ZD_RELEASE_BEFORE_MINIMUM_PROTOCOL = "v0.1.16"
24
27
 
25
28
 
@@ -108,6 +111,15 @@ class NegotiatedServerProtocol:
108
111
  "the default task queue"
109
112
  )
110
113
 
114
+ def require_clone_fork_flow_support(self) -> None:
115
+ if self._version >= CLONE_FORK_FLOW_PROTOCOL_VERSION:
116
+ return
117
+ raise CloneForkFlowUnsupportedError(
118
+ self._version,
119
+ CLONE_FORK_FLOW_PROTOCOL_VERSION,
120
+ CLONE_FORK_FLOW_SERVER_ZD_RELEASE,
121
+ )
122
+
111
123
 
112
124
  def server_info_request_error(
113
125
  artifact_version: str, failure: grpc.RpcError
@@ -30,7 +30,16 @@ from dex._flow_definition_upload import (
30
30
  upload_requests,
31
31
  upload_results_from_response,
32
32
  )
33
- from dex._grpc_errors import FlowTargetRequirement, translate_rpc_error
33
+ from dex._grpc_errors import (
34
+ FlowTargetRequirement,
35
+ translate_clone_fork_flow_error,
36
+ translate_rpc_error,
37
+ )
38
+ from dex._history_point_mapping import (
39
+ clone_fork_flow_result_from_proto,
40
+ map_clone_fork_flow_request,
41
+ map_time_travel_request,
42
+ )
34
43
  from dex._server_protocol import (
35
44
  NegotiatedServerProtocol,
36
45
  ServerProtocolNegotiationTimeoutError,
@@ -67,14 +76,15 @@ from dex.flow_config import ActiveStepSearchMode, FlowConfig
67
76
  from dex.flow_info import FlowInfo, FlowStatus, SearchFlowEntry, SearchFlowsPage
68
77
  from dex.flow_state import FlowState, flow_state_from_proto
69
78
  from dex.flow_options import (
79
+ CloneForkFlowOptions,
80
+ CloneForkFlowResult,
70
81
  FlowTimeoutPolicy,
71
82
  IdReusePolicy,
72
83
  StartFlowOptions,
73
84
  StopFlowOptions,
74
85
  StopType,
75
86
  TimeTravelOptions,
76
- TimeTravelStepMethod,
77
- TimeTravelType,
87
+ _AttributeInitialization,
78
88
  _resolve_flow_timeout_policy,
79
89
  )
80
90
  from dex.flow_result import FlowResult, flow_result_from_proto
@@ -985,29 +995,12 @@ class AsyncClient:
985
995
  ValueError: If time travel selector fields are invalid.
986
996
  DexServiceError: If FlowService cannot perform the time travel.
987
997
  RuntimeError: If the Server reports a protocol range without protocol 4.
998
+
999
+ .. versionchanged:: 1.45.3
1000
+ Accepts ``TimeTravelType.EVENT_ID`` with ``options.event_id`` and
1001
+ sends ``options.sub_flow_reset_policy``.
988
1002
  """
989
- request = pb.ResetFlowRequest(
990
- flow_id=require_name(flow_id),
991
- reset_type={
992
- TimeTravelType.BEGINNING: pb.FLOW_RESET_TYPE_BEGINNING,
993
- TimeTravelType.HISTORY_EVENT_TIME: pb.FLOW_RESET_TYPE_HISTORY_EVENT_TIME,
994
- TimeTravelType.STEP_TYPE: pb.FLOW_RESET_TYPE_STEP_TYPE,
995
- TimeTravelType.STEP_EXECUTION_ID: pb.FLOW_RESET_TYPE_STEP_EXECUTION_ID,
996
- }[options.type],
997
- reason=options.reason or "",
998
- skip_writes_reapply=options.skip_writes_reapply,
999
- )
1000
- if options.history_event_time is not None:
1001
- request.history_event_time = options.history_event_time.isoformat()
1002
- if options.step_type is not None:
1003
- request.step_type = options.step_type
1004
- if options.step_execution_id is not None:
1005
- request.step_execution_id = options.step_execution_id
1006
- if options.step_method is not None:
1007
- request.step_method = {
1008
- TimeTravelStepMethod.WAIT_FOR: pb.FLOW_RESET_STEP_METHOD_WAIT_FOR,
1009
- TimeTravelStepMethod.EXECUTE: pb.FLOW_RESET_STEP_METHOD_EXECUTE,
1010
- }[options.step_method]
1003
+ request = map_time_travel_request(require_name(flow_id), options)
1011
1004
  response = cast(
1012
1005
  pb.ResetFlowResponse,
1013
1006
  await self._call(
@@ -1020,6 +1013,98 @@ class AsyncClient:
1020
1013
  )
1021
1014
  return response.run_id
1022
1015
 
1016
+ async def clone_fork_flow(
1017
+ self,
1018
+ flow: Flow[Any],
1019
+ source_flow_id: str,
1020
+ flow_id: str,
1021
+ options: CloneForkFlowOptions = CloneForkFlowOptions(),
1022
+ ) -> CloneForkFlowResult:
1023
+ """Create a new Flow whose first run starts from a copy of another run.
1024
+
1025
+ This is the asynchronous form of :meth:`dex.Client.clone_fork_flow`; it
1026
+ takes the same arguments, returns the same result, and raises the same
1027
+ errors.
1028
+
1029
+ The source run is the run of ``source_flow_id`` that
1030
+ ``options.source_run_id`` selects; the empty default selects the latest
1031
+ run. ``options`` selects the copied point, as for ``time_travel``; the
1032
+ default copies the latest committed state. The new Flow gets the Flow
1033
+ ID ``flow_id``, a new run ID, and run attempt 1, and continues on its
1034
+ own from the copied state. The source run keeps running and never
1035
+ changes.
1036
+
1037
+ Args:
1038
+ flow: The registered Flow instance of the source run's Flow type.
1039
+ The new Flow keeps that type. The Client uses it to encode the
1040
+ Attribute writes of ``options``.
1041
+ source_flow_id: The non-empty Flow ID of the source run.
1042
+ flow_id: The non-empty Flow ID of the new Flow. It must differ from
1043
+ ``source_flow_id``.
1044
+ options: The copied point and the new Flow's start settings.
1045
+
1046
+ Returns:
1047
+ The new run ID and the source run, run attempt, and last history
1048
+ event ID that the copied point includes.
1049
+
1050
+ Raises:
1051
+ CloneForkFlowUnsupportedError: If the Server negotiated a protocol
1052
+ older than version 6; server-zd 0.1.33 and later support it.
1053
+ The request is not sent.
1054
+ FlowAlreadyStartedError: If the ID reuse policy rejects a run of
1055
+ ``flow_id``.
1056
+ FlowNotFoundError: If the source run does not exist. Its
1057
+ ``flow_id`` is ``source_flow_id``.
1058
+ FlowDefinitionError: If ``flow`` is not registered.
1059
+ ValueError: If a Flow ID is empty or both Flow IDs are equal.
1060
+ ValueMappingError: If an Attribute write cannot be encoded.
1061
+ DexServiceError: If FlowService rejects the call, for example with
1062
+ ``FAILED_PRECONDITION`` when the point is outside the source
1063
+ run's history window or its state is not running.
1064
+
1065
+ Examples:
1066
+ >>> result = await client.clone_fork_flow(
1067
+ ... session_flow,
1068
+ ... "session-1",
1069
+ ... "session-1-branch",
1070
+ ... CloneForkFlowOptions(type=TimeTravelType.EVENT_ID, event_id=42),
1071
+ ... )
1072
+ >>> print(result.run_id, result.source_event_id)
1073
+
1074
+ .. versionadded:: 1.45.3
1075
+ """
1076
+ registered = self.registry._flow_for_instance(flow)
1077
+ require_name(source_flow_id)
1078
+ require_name(flow_id)
1079
+ if source_flow_id == flow_id:
1080
+ raise ValueError(
1081
+ "clone_fork_flow flow_id must differ from source_flow_id; "
1082
+ "use time_travel to return a Flow to an earlier point"
1083
+ )
1084
+ request = map_clone_fork_flow_request(
1085
+ source_flow_id,
1086
+ flow_id,
1087
+ options,
1088
+ self._map_clone_fork_flow_config_override(options),
1089
+ self._map_attribute_initializations(
1090
+ registered, options._attribute_initializations
1091
+ ),
1092
+ 0 if options.timeout is None else self._seconds32(options.timeout),
1093
+ )
1094
+ await self._negotiate_server_protocol_for_operation(
1095
+ "clone_fork_flow", flow_id, "none"
1096
+ )
1097
+ self._server_protocol.require_clone_fork_flow_support()
1098
+ try:
1099
+ response = cast(
1100
+ pb.CloneForkFlowResponse, await self._service.CloneForkFlow(request)
1101
+ )
1102
+ except grpc.RpcError as error:
1103
+ raise translate_clone_fork_flow_error(
1104
+ error, source_flow_id, flow_id
1105
+ ) from error
1106
+ return clone_fork_flow_result_from_proto(response)
1107
+
1023
1108
  async def skip_timer(
1024
1109
  self,
1025
1110
  flow_id: str,
@@ -1556,7 +1641,29 @@ class AsyncClient:
1556
1641
  mapped.flow_start_delay_seconds = self._seconds32(options.start_delay)
1557
1642
  if options.retry_policy is not None:
1558
1643
  mapped.retry_policy.CopyFrom(self._map_flow_retry(options.retry_policy))
1559
- for initialization in options._attribute_initializations:
1644
+ mapped.attributes.extend(
1645
+ self._map_attribute_initializations(
1646
+ registered, options._attribute_initializations
1647
+ )
1648
+ )
1649
+ mapped.attributes.extend(
1650
+ registered.initial_work_queue_permissions_writes(mapped.attributes)
1651
+ )
1652
+ mapped.flow_config_override.CopyFrom(
1653
+ self._map_flow_config(options.config_override)
1654
+ )
1655
+ mapped.flow_config_override.worker_target.CopyFrom(
1656
+ pb.WorkerTarget(is_pull_mode=True, task_queue=options.task_queue)
1657
+ )
1658
+ return mapped
1659
+
1660
+ def _map_attribute_initializations(
1661
+ self,
1662
+ registered: _RegisteredFlow,
1663
+ initializations: tuple[_AttributeInitialization, ...],
1664
+ ) -> list[pb.AttributeWrite]:
1665
+ writes: list[pb.AttributeWrite] = []
1666
+ for initialization in initializations:
1560
1667
  definition = initialization.definition
1561
1668
  _require_matching_hard_delete_on_null(
1562
1669
  registered.name, registered.persistence.get(definition.name), definition
@@ -1571,16 +1678,20 @@ class AsyncClient:
1571
1678
  )
1572
1679
  _apply_attribute_store_sync(write, definition)
1573
1680
  _apply_hard_delete_on_null(write, definition)
1574
- mapped.attributes.append(write)
1575
- mapped.attributes.extend(
1576
- registered.initial_work_queue_permissions_writes(mapped.attributes)
1577
- )
1578
- mapped.flow_config_override.CopyFrom(
1579
- self._map_flow_config(options.config_override)
1580
- )
1581
- mapped.flow_config_override.worker_target.CopyFrom(
1582
- pb.WorkerTarget(is_pull_mode=True, task_queue=options.task_queue)
1583
- )
1681
+ writes.append(write)
1682
+ return writes
1683
+
1684
+ def _map_clone_fork_flow_config_override(
1685
+ self, options: CloneForkFlowOptions
1686
+ ) -> pb.FlowConfig | None:
1687
+ # No override keeps every FlowConfig value of the source run.
1688
+ if options.config_override is None and not options.task_queue:
1689
+ return None
1690
+ mapped = self._map_flow_config(options.config_override)
1691
+ if options.task_queue:
1692
+ mapped.worker_target.CopyFrom(
1693
+ pb.WorkerTarget(is_pull_mode=True, task_queue=options.task_queue)
1694
+ )
1584
1695
  return mapped
1585
1696
 
1586
1697
  def _map_flow_config(self, config: FlowConfig | None) -> pb.FlowConfig:
@@ -1743,6 +1854,9 @@ class AsyncClient:
1743
1854
  ),
1744
1855
  int(pb.FLOW_ERROR_TYPE_INTERNAL): FlowErrorType.INTERNAL,
1745
1856
  int(pb.FLOW_ERROR_TYPE_FLOW_TIMEOUT): FlowErrorType.FLOW_TIMEOUT,
1857
+ int(pb.FLOW_ERROR_TYPE_SUB_FLOW_ABANDONED): (
1858
+ FlowErrorType.SUB_FLOW_ABANDONED
1859
+ ),
1746
1860
  }
1747
1861
  return error_types.get(error_type)
1748
1862