Skip to content

Commit 71a3012

Browse files
committed
Update EntityInstanceId.parse signature
1 parent b4086fd commit 71a3012

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

durabletask/entities/entity_instance_id.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __lt__(self, other):
2020
return str(self) < str(other)
2121

2222
@staticmethod
23-
def parse(entity_id: str) -> Optional["EntityInstanceId"]:
23+
def parse(entity_id: str) -> "EntityInstanceId":
2424
"""Parse a string representation of an entity ID into an EntityInstanceId object.
2525
2626
Parameters

durabletask/entities/entity_metadata.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ def __init__(self,
4444

4545
@staticmethod
4646
def from_entity_response(entity_response: pb.GetEntityResponse, includes_state: bool):
47-
entity_id = EntityInstanceId.parse(entity_response.entity.instanceId)
48-
if not entity_id:
47+
try:
48+
entity_id = EntityInstanceId.parse(entity_response.entity.instanceId)
49+
except ValueError:
4950
raise ValueError("Invalid entity instance ID in entity response.")
5051
entity_state = None
5152
if includes_state:

durabletask/worker.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,9 @@ def _execute_entity_batch(
750750
for operation in req.operations:
751751
start_time = datetime.now(timezone.utc)
752752
executor = _EntityExecutor(self._registry, self._logger)
753-
entity_instance_id = EntityInstanceId.parse(instance_id)
754-
if not entity_instance_id:
753+
try:
754+
entity_instance_id = EntityInstanceId.parse(instance_id)
755+
except ValueError:
755756
raise RuntimeError(f"Invalid entity instance ID '{operation.requestId}' in entity operation request.")
756757

757758
operation_result = None
@@ -1656,8 +1657,9 @@ def process_event(
16561657
raise _get_wrong_action_type_error(
16571658
entity_call_id, expected_method_name, action
16581659
)
1659-
entity_id = EntityInstanceId.parse(event.entityOperationCalled.targetInstanceId.value)
1660-
if not entity_id:
1660+
try:
1661+
entity_id = EntityInstanceId.parse(event.entityOperationCalled.targetInstanceId.value)
1662+
except ValueError:
16611663
raise RuntimeError(f"Could not parse entity ID from targetInstanceId '{event.entityOperationCalled.targetInstanceId.value}'")
16621664
ctx._entity_task_id_map[event.entityOperationCalled.requestId] = (entity_id, entity_call_id)
16631665
elif event.HasField("entityOperationSignaled"):

0 commit comments

Comments
 (0)