durabletask 1.3.0.dev14__tar.gz → 1.3.0.dev15__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 (34) hide show
  1. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/PKG-INFO +1 -1
  2. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/entities/__init__.py +3 -1
  3. durabletask-1.3.0.dev15/durabletask/entities/entity_instance_id.py +84 -0
  4. durabletask-1.3.0.dev15/durabletask/entities/entity_operation_failed_exception.py +15 -0
  5. durabletask-1.3.0.dev15/durabletask/internal/json_encode_output_exception.py +12 -0
  6. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/worker.py +41 -19
  7. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask.egg-info/PKG-INFO +1 -1
  8. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask.egg-info/SOURCES.txt +2 -0
  9. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/pyproject.toml +1 -1
  10. durabletask-1.3.0.dev14/durabletask/entities/entity_instance_id.py +0 -42
  11. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/LICENSE +0 -0
  12. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/README.md +0 -0
  13. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/__init__.py +0 -0
  14. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/client.py +0 -0
  15. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/entities/durable_entity.py +0 -0
  16. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/entities/entity_context.py +0 -0
  17. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/entities/entity_lock.py +0 -0
  18. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/entities/entity_metadata.py +0 -0
  19. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/internal/entity_state_shim.py +0 -0
  20. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/internal/exceptions.py +0 -0
  21. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/internal/grpc_interceptor.py +0 -0
  22. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/internal/helpers.py +0 -0
  23. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/internal/orchestration_entity_context.py +0 -0
  24. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/internal/orchestrator_service_pb2.py +0 -0
  25. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/internal/orchestrator_service_pb2.pyi +0 -0
  26. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/internal/orchestrator_service_pb2_grpc.py +0 -0
  27. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/internal/proto_task_hub_sidecar_service_stub.py +0 -0
  28. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/internal/shared.py +0 -0
  29. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/py.typed +0 -0
  30. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask/task.py +0 -0
  31. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask.egg-info/dependency_links.txt +0 -0
  32. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask.egg-info/requires.txt +0 -0
  33. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/durabletask.egg-info/top_level.txt +0 -0
  34. {durabletask-1.3.0.dev14 → durabletask-1.3.0.dev15}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: durabletask
3
- Version: 1.3.0.dev14
3
+ Version: 1.3.0.dev15
4
4
  Summary: A Durable Task Client SDK for Python
5
5
  License: MIT License
6
6
 
@@ -8,7 +8,9 @@ from durabletask.entities.durable_entity import DurableEntity
8
8
  from durabletask.entities.entity_lock import EntityLock
9
9
  from durabletask.entities.entity_context import EntityContext
10
10
  from durabletask.entities.entity_metadata import EntityMetadata
11
+ from durabletask.entities.entity_operation_failed_exception import EntityOperationFailedException
11
12
 
12
- __all__ = ["EntityInstanceId", "DurableEntity", "EntityLock", "EntityContext", "EntityMetadata"]
13
+ __all__ = ["EntityInstanceId", "DurableEntity", "EntityLock", "EntityContext", "EntityMetadata",
14
+ "EntityOperationFailedException"]
13
15
 
14
16
  PACKAGE_NAME = "durabletask.entities"
@@ -0,0 +1,84 @@
1
+ class EntityInstanceId:
2
+ def __init__(self, entity: str, key: str):
3
+ EntityInstanceId.validate_entity_name(entity)
4
+ EntityInstanceId.validate_key(key)
5
+ self.entity = entity.lower()
6
+ self.key = key
7
+
8
+ def __str__(self) -> str:
9
+ return f"@{self.entity}@{self.key}"
10
+
11
+ def __eq__(self, other):
12
+ if not isinstance(other, EntityInstanceId):
13
+ return False
14
+ return self.entity == other.entity and self.key == other.key
15
+
16
+ def __lt__(self, other):
17
+ if not isinstance(other, EntityInstanceId):
18
+ return self < other
19
+ return str(self) < str(other)
20
+
21
+ @staticmethod
22
+ def parse(entity_id: str) -> "EntityInstanceId":
23
+ """Parse a string representation of an entity ID into an EntityInstanceId object.
24
+
25
+ Parameters
26
+ ----------
27
+ entity_id : str
28
+ The string representation of the entity ID, in the format '@entity@key'.
29
+
30
+ Returns
31
+ -------
32
+ EntityInstanceId
33
+ The parsed EntityInstanceId object.
34
+
35
+ Raises
36
+ ------
37
+ ValueError
38
+ If the input string is not in the correct format.
39
+ """
40
+ if not entity_id.startswith("@"):
41
+ raise ValueError("Entity ID must start with '@'.")
42
+ try:
43
+ _, entity, key = entity_id.split("@", 2)
44
+ except ValueError as ex:
45
+ raise ValueError(f"Invalid entity ID format: {entity_id}") from ex
46
+ return EntityInstanceId(entity=entity, key=key)
47
+
48
+ @staticmethod
49
+ def validate_entity_name(name: str) -> None:
50
+ """Validate that the entity name does not contain invalid characters.
51
+
52
+ Parameters
53
+ ----------
54
+ name : str
55
+ The entity name to validate.
56
+
57
+ Raises
58
+ ------
59
+ ValueError
60
+ If the name is not a valid entity name.
61
+ """
62
+ if not name:
63
+ raise ValueError("Entity name cannot be empty.")
64
+ if "@" in name:
65
+ raise ValueError("Entity name cannot contain '@' symbol.")
66
+
67
+ @staticmethod
68
+ def validate_key(key: str) -> None:
69
+ """Validate that the entity key does not contain invalid characters.
70
+
71
+ Parameters
72
+ ----------
73
+ key : str
74
+ The entity key to validate.
75
+
76
+ Raises
77
+ ------
78
+ ValueError
79
+ If the key is not a valid entity key.
80
+ """
81
+ if not key:
82
+ raise ValueError("Entity key cannot be empty.")
83
+ if "@" in key:
84
+ raise ValueError("Entity key cannot contain '@' symbol.")
@@ -0,0 +1,15 @@
1
+ from durabletask.internal.orchestrator_service_pb2 import TaskFailureDetails
2
+ from durabletask.entities.entity_instance_id import EntityInstanceId
3
+
4
+
5
+ class EntityOperationFailedException(Exception):
6
+ """Exception raised when an operation on an Entity Function fails."""
7
+
8
+ def __init__(self, entity_instance_id: EntityInstanceId, operation_name: str, failure_details: TaskFailureDetails) -> None:
9
+ super().__init__()
10
+ self.entity_instance_id = entity_instance_id
11
+ self.operation_name = operation_name
12
+ self.failure_details = failure_details
13
+
14
+ def __str__(self) -> str:
15
+ return f"Operation '{self.operation_name}' on entity '{self.entity_instance_id}' failed with error: {self.failure_details.errorMessage}"
@@ -0,0 +1,12 @@
1
+ from typing import Any
2
+
3
+
4
+ class JsonEncodeOutputException(Exception):
5
+ """Custom exception type used to indicate that an orchestration result could not be JSON-encoded."""
6
+
7
+ def __init__(self, problem_object: Any):
8
+ super().__init__()
9
+ self.problem_object = problem_object
10
+
11
+ def __str__(self) -> str:
12
+ return f"The orchestration result could not be encoded. Object details: {self.problem_object}"
@@ -19,10 +19,12 @@ from packaging.version import InvalidVersion, parse
19
19
  import grpc
20
20
  from google.protobuf import empty_pb2
21
21
 
22
+ from durabletask.entities.entity_operation_failed_exception import EntityOperationFailedException
22
23
  from durabletask.internal import helpers
23
24
  from durabletask.internal.entity_state_shim import StateShim
24
25
  from durabletask.internal.helpers import new_timestamp
25
26
  from durabletask.entities import DurableEntity, EntityLock, EntityInstanceId, EntityContext
27
+ from durabletask.internal.json_encode_output_exception import JsonEncodeOutputException
26
28
  from durabletask.internal.orchestration_entity_context import OrchestrationEntityContext
27
29
  from durabletask.internal.proto_task_hub_sidecar_service_stub import ProtoTaskHubSidecarServiceStub
28
30
  import durabletask.internal.helpers as ph
@@ -141,14 +143,12 @@ class _Registry:
141
143
  orchestrators: dict[str, task.Orchestrator]
142
144
  activities: dict[str, task.Activity]
143
145
  entities: dict[str, task.Entity]
144
- entity_instances: dict[str, DurableEntity]
145
146
  versioning: Optional[VersioningOptions] = None
146
147
 
147
148
  def __init__(self):
148
149
  self.orchestrators = {}
149
150
  self.activities = {}
150
151
  self.entities = {}
151
- self.entity_instances = {}
152
152
 
153
153
  def add_orchestrator(self, fn: task.Orchestrator[TInput, TOutput]) -> str:
154
154
  if fn is None:
@@ -199,8 +199,8 @@ class _Registry:
199
199
  return name
200
200
 
201
201
  def add_named_entity(self, name: str, fn: task.Entity) -> None:
202
- if not name:
203
- raise ValueError("A non-empty entity name is required.")
202
+ name = name.lower()
203
+ EntityInstanceId.validate_entity_name(name)
204
204
  if name in self.entities:
205
205
  raise ValueError(f"A '{name}' entity already exists.")
206
206
 
@@ -829,7 +829,7 @@ class _RuntimeOrchestrationContext(task.OrchestrationContext):
829
829
  self._pending_actions: dict[int, pb.OrchestratorAction] = {}
830
830
  self._pending_tasks: dict[int, task.CompletableTask] = {}
831
831
  # Maps entity ID to task ID
832
- self._entity_task_id_map: dict[str, tuple[EntityInstanceId, int]] = {}
832
+ self._entity_task_id_map: dict[str, tuple[EntityInstanceId, str, int]] = {}
833
833
  self._entity_lock_task_id_map: dict[str, tuple[EntityInstanceId, int]] = {}
834
834
  # Maps criticalSectionId to task ID
835
835
  self._entity_lock_id_map: dict[str, int] = {}
@@ -902,7 +902,13 @@ class _RuntimeOrchestrationContext(task.OrchestrationContext):
902
902
  self._result = result
903
903
  result_json: Optional[str] = None
904
904
  if result is not None:
905
- result_json = result if is_result_encoded else shared.to_json(result)
905
+ try:
906
+ result_json = result if is_result_encoded else shared.to_json(result)
907
+ except (ValueError, TypeError):
908
+ self._is_complete = False
909
+ self._result = None
910
+ self.set_failed(JsonEncodeOutputException(result))
911
+ return
906
912
  action = ph.new_complete_orchestration_action(
907
913
  self.next_sequence_number(), status, result_json
908
914
  )
@@ -1606,7 +1612,7 @@ class _OrchestrationExecutor:
1606
1612
  raise TypeError("Unexpected sub-orchestration task type")
1607
1613
  elif event.HasField("eventRaised"):
1608
1614
  if event.eventRaised.name in ctx._entity_task_id_map:
1609
- entity_id, task_id = ctx._entity_task_id_map.get(event.eventRaised.name, (None, None))
1615
+ entity_id, operation, task_id = ctx._entity_task_id_map.get(event.eventRaised.name, (None, None, None))
1610
1616
  self._handle_entity_event_raised(ctx, event, entity_id, task_id, False)
1611
1617
  elif event.eventRaised.name in ctx._entity_lock_task_id_map:
1612
1618
  entity_id, task_id = ctx._entity_lock_task_id_map.get(event.eventRaised.name, (None, None))
@@ -1680,9 +1686,10 @@ class _OrchestrationExecutor:
1680
1686
  )
1681
1687
  try:
1682
1688
  entity_id = EntityInstanceId.parse(event.entityOperationCalled.targetInstanceId.value)
1689
+ operation = event.entityOperationCalled.operation
1683
1690
  except ValueError:
1684
1691
  raise RuntimeError(f"Could not parse entity ID from targetInstanceId '{event.entityOperationCalled.targetInstanceId.value}'")
1685
- ctx._entity_task_id_map[event.entityOperationCalled.requestId] = (entity_id, entity_call_id)
1692
+ ctx._entity_task_id_map[event.entityOperationCalled.requestId] = (entity_id, operation, entity_call_id)
1686
1693
  elif event.HasField("entityOperationSignaled"):
1687
1694
  # This history event confirms that the entity signal was successfully scheduled.
1688
1695
  # Remove the entityOperationSignaled event from the pending action list so we don't schedule it
@@ -1743,7 +1750,7 @@ class _OrchestrationExecutor:
1743
1750
  ctx.resume()
1744
1751
  elif event.HasField("entityOperationCompleted"):
1745
1752
  request_id = event.entityOperationCompleted.requestId
1746
- entity_id, task_id = ctx._entity_task_id_map.pop(request_id, (None, None))
1753
+ entity_id, operation, task_id = ctx._entity_task_id_map.pop(request_id, (None, None, None))
1747
1754
  if not entity_id:
1748
1755
  raise RuntimeError(f"Could not parse entity ID from request ID '{request_id}'")
1749
1756
  if not task_id:
@@ -1762,10 +1769,29 @@ class _OrchestrationExecutor:
1762
1769
  entity_task.complete(result)
1763
1770
  ctx.resume()
1764
1771
  elif event.HasField("entityOperationFailed"):
1765
- if not ctx.is_replaying:
1766
- self._logger.info(f"{ctx.instance_id}: Entity operation failed.")
1767
- self._logger.info(f"Data: {json.dumps(event.entityOperationFailed)}")
1768
- pass
1772
+ request_id = event.entityOperationFailed.requestId
1773
+ entity_id, operation, task_id = ctx._entity_task_id_map.pop(request_id, (None, None, None))
1774
+ if not entity_id:
1775
+ raise RuntimeError(f"Could not parse entity ID from request ID '{request_id}'")
1776
+ if operation is None:
1777
+ raise RuntimeError(f"Could not parse operation name from request ID '{request_id}'")
1778
+ if not task_id:
1779
+ raise RuntimeError(f"Could not find matching task ID for entity operation with request ID '{request_id}'")
1780
+ entity_task = ctx._pending_tasks.pop(task_id, None)
1781
+ if not entity_task:
1782
+ if not ctx.is_replaying:
1783
+ self._logger.warning(
1784
+ f"{ctx.instance_id}: Ignoring unexpected entityOperationFailed event with request ID = {request_id}."
1785
+ )
1786
+ return
1787
+ failure = EntityOperationFailedException(
1788
+ entity_id,
1789
+ operation,
1790
+ event.entityOperationFailed.failureDetails
1791
+ )
1792
+ ctx._entity_context.recover_lock_after_call(entity_id)
1793
+ entity_task.fail(str(failure), failure)
1794
+ ctx.resume()
1769
1795
  elif event.HasField("orchestratorCompleted"):
1770
1796
  # Added in Functions only (for some reason) and does not affect orchestrator flow
1771
1797
  pass
@@ -1777,7 +1803,7 @@ class _OrchestrationExecutor:
1777
1803
  if action and action.HasField("sendEntityMessage"):
1778
1804
  if action.sendEntityMessage.HasField("entityOperationCalled"):
1779
1805
  entity_id, event_id = self._parse_entity_event_sent_input(event)
1780
- ctx._entity_task_id_map[event_id] = (entity_id, event.eventId)
1806
+ ctx._entity_task_id_map[event_id] = (entity_id, action.sendEntityMessage.entityOperationCalled.operation, event.eventId)
1781
1807
  elif action.sendEntityMessage.HasField("entityLockRequested"):
1782
1808
  entity_id, event_id = self._parse_entity_event_sent_input(event)
1783
1809
  ctx._entity_lock_task_id_map[event_id] = (entity_id, event.eventId)
@@ -1937,11 +1963,7 @@ class _EntityExecutor:
1937
1963
  ctx = EntityContext(orchestration_id, operation, state, entity_id)
1938
1964
 
1939
1965
  if isinstance(fn, type) and issubclass(fn, DurableEntity):
1940
- if self._registry.entity_instances.get(str(entity_id), None):
1941
- entity_instance = self._registry.entity_instances[str(entity_id)]
1942
- else:
1943
- entity_instance = fn()
1944
- self._registry.entity_instances[str(entity_id)] = entity_instance
1966
+ entity_instance = fn()
1945
1967
  if not hasattr(entity_instance, operation):
1946
1968
  raise AttributeError(f"Entity '{entity_id}' does not have operation '{operation}'")
1947
1969
  method = getattr(entity_instance, operation)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: durabletask
3
- Version: 1.3.0.dev14
3
+ Version: 1.3.0.dev15
4
4
  Summary: A Durable Task Client SDK for Python
5
5
  License: MIT License
6
6
 
@@ -17,10 +17,12 @@ durabletask/entities/entity_context.py
17
17
  durabletask/entities/entity_instance_id.py
18
18
  durabletask/entities/entity_lock.py
19
19
  durabletask/entities/entity_metadata.py
20
+ durabletask/entities/entity_operation_failed_exception.py
20
21
  durabletask/internal/entity_state_shim.py
21
22
  durabletask/internal/exceptions.py
22
23
  durabletask/internal/grpc_interceptor.py
23
24
  durabletask/internal/helpers.py
25
+ durabletask/internal/json_encode_output_exception.py
24
26
  durabletask/internal/orchestration_entity_context.py
25
27
  durabletask/internal/orchestrator_service_pb2.py
26
28
  durabletask/internal/orchestrator_service_pb2.pyi
@@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta"
9
9
 
10
10
  [project]
11
11
  name = "durabletask"
12
- version = "1.3.0.dev14"
12
+ version = "1.3.0.dev15"
13
13
  description = "A Durable Task Client SDK for Python"
14
14
  keywords = [
15
15
  "durable",
@@ -1,42 +0,0 @@
1
- class EntityInstanceId:
2
- def __init__(self, entity: str, key: str):
3
- self.entity = entity
4
- self.key = key
5
-
6
- def __str__(self) -> str:
7
- return f"@{self.entity}@{self.key}"
8
-
9
- def __eq__(self, other):
10
- if not isinstance(other, EntityInstanceId):
11
- return False
12
- return self.entity == other.entity and self.key == other.key
13
-
14
- def __lt__(self, other):
15
- if not isinstance(other, EntityInstanceId):
16
- return self < other
17
- return str(self) < str(other)
18
-
19
- @staticmethod
20
- def parse(entity_id: str) -> "EntityInstanceId":
21
- """Parse a string representation of an entity ID into an EntityInstanceId object.
22
-
23
- Parameters
24
- ----------
25
- entity_id : str
26
- The string representation of the entity ID, in the format '@entity@key'.
27
-
28
- Returns
29
- -------
30
- EntityInstanceId
31
- The parsed EntityInstanceId object.
32
-
33
- Raises
34
- ------
35
- ValueError
36
- If the input string is not in the correct format.
37
- """
38
- try:
39
- _, entity, key = entity_id.split("@", 2)
40
- return EntityInstanceId(entity=entity, key=key)
41
- except ValueError as ex:
42
- raise ValueError(f"Invalid entity ID format: {entity_id}", ex)