Skip to content

Commit ffdabaa

Browse files
committed
PR feedback
1 parent b97434d commit ffdabaa

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

durabletask/entities/entity_instance_id.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
class EntityInstanceId:
22
def __init__(self, entity: str, key: str):
3+
if not entity or not key:
4+
raise ValueError("Entity name and key cannot be empty.")
5+
if "@" in key:
6+
raise ValueError("Entity key cannot contain '@' symbol.")
37
self.entity = entity.lower()
48
self.key = key
59

@@ -35,14 +39,10 @@ def parse(entity_id: str) -> "EntityInstanceId":
3539
ValueError
3640
If the input string is not in the correct format.
3741
"""
42+
if not entity_id.startswith("@"):
43+
raise ValueError("Entity ID must start with '@'.")
3844
try:
39-
if not entity_id.startswith("@"):
40-
raise ValueError("Entity ID must start with '@'.")
4145
_, entity, key = entity_id.split("@", 2)
42-
if not entity or not key:
43-
raise ValueError("Entity name and key cannot be empty.")
44-
if "@" in key:
45-
raise ValueError("Entity instance ID string should not contain more than two '@' symbols.")
46-
return EntityInstanceId(entity=entity, key=key)
4746
except ValueError as ex:
48-
raise ValueError(f"Invalid entity ID format: {entity_id}", ex)
47+
raise ValueError(f"Invalid entity ID format: {entity_id}") from ex
48+
return EntityInstanceId(entity=entity, key=key)

durabletask/worker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ def set_complete(
905905
if result is not None:
906906
try:
907907
result_json = result if is_result_encoded else shared.to_json(result)
908-
except TypeError:
908+
except (ValueError, TypeError):
909909
result_json = shared.to_json(str(JsonEncodeOutputException(result)))
910910
action = ph.new_complete_orchestration_action(
911911
self.next_sequence_number(), status, result_json
@@ -1779,7 +1779,7 @@ def process_event(
17791779
if not entity_task:
17801780
if not ctx.is_replaying:
17811781
self._logger.warning(
1782-
f"{ctx.instance_id}: Ignoring unexpected entityOperationCompleted event with request ID = {request_id}."
1782+
f"{ctx.instance_id}: Ignoring unexpected entityOperationFailed event with request ID = {request_id}."
17831783
)
17841784
return
17851785
failure = EntityOperationFailedException(
@@ -1801,7 +1801,7 @@ def process_event(
18011801
if action and action.HasField("sendEntityMessage"):
18021802
if action.sendEntityMessage.HasField("entityOperationCalled"):
18031803
entity_id, event_id = self._parse_entity_event_sent_input(event)
1804-
ctx._entity_task_id_map[event_id] = (entity_id, event.entityOperationCalled.operation, event.eventId)
1804+
ctx._entity_task_id_map[event_id] = (entity_id, action.sendEntityMessage.entityOperationCalled.operation, event.eventId)
18051805
elif action.sendEntityMessage.HasField("entityLockRequested"):
18061806
entity_id, event_id = self._parse_entity_event_sent_input(event)
18071807
ctx._entity_lock_task_id_map[event_id] = (entity_id, event.eventId)

tests/durabletask-azuremanaged/entities/test_dts_entity_failure_handling.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ def test_orchestrator(ctx: task.OrchestrationContext, _):
8686
try:
8787
yield ctx.call_entity(entity_id, "fail")
8888
except task.TaskFailedError as e:
89-
# Need to return the exception wrapped in a list to avoid
90-
# https://github.com/microsoft/durabletask-python/issues/108
9189
return e.details.message # returning just the message to avoid issues with JSON serialization of FailureDetails
9290

9391
# Start a worker, which will connect to the sidecar in a background thread
@@ -157,11 +155,11 @@ def test_orchestrator(ctx: task.OrchestrationContext, _):
157155
with (yield ctx.lock_entities([entity_id])):
158156
try:
159157
yield ctx.call_entity(entity_id, "fail")
160-
except task.TaskFailedError as e:
158+
except task.TaskFailedError:
161159
exception_count += 1
162160
try:
163161
yield ctx.call_entity(entity_id, "fail")
164-
except task.TaskFailedError as e:
162+
except task.TaskFailedError:
165163
exception_count += 1
166164
return exception_count
167165

0 commit comments

Comments
 (0)