Skip to content

Commit 0123fdb

Browse files
committed
style: appease linter
Signed-off-by: Samantha Coyle <sam@diagrid.io>
1 parent 56775eb commit 0123fdb

3 files changed

Lines changed: 37 additions & 39 deletions

File tree

ext/dapr-ext-workflow/dapr/ext/workflow/aio/mcp.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,10 @@ async def connect(self, mcpserver_name: str) -> None:
104104
except Exception as exc: # noqa: BLE001 — classified by helper
105105
if not _is_transient_schedule_error(exc):
106106
raise
107-
sleep_for = min(
108-
_SCHEDULE_RETRY_INTERVAL_SECONDS, deadline - time.monotonic()
109-
)
107+
sleep_for = min(_SCHEDULE_RETRY_INTERVAL_SECONDS, deadline - time.monotonic())
110108
if sleep_for <= 0:
111109
raise
112-
logger.debug(
113-
'schedule_new_workflow returned transient error %s; retrying', exc
114-
)
110+
logger.debug('schedule_new_workflow returned transient error %s; retrying', exc)
115111
await asyncio.sleep(sleep_for)
116112

117113
remaining = deadline - time.monotonic()

ext/dapr-ext-workflow/dapr/ext/workflow/mcp.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from typing import Any, Dict, List, Optional, Set
4040

4141
import grpc
42-
4342
from dapr.ext.workflow.dapr_workflow_client import DaprWorkflowClient
4443
from dapr.ext.workflow.workflow_state import WorkflowStatus
4544

@@ -53,10 +52,12 @@
5352
_MCP_METHOD_LIST_TOOLS = '.ListTools'
5453
_MCP_METHOD_CALL_TOOL = '.CallTool'
5554

56-
_TRANSIENT_GRPC_CODES = frozenset({
57-
grpc.StatusCode.CANCELLED,
58-
grpc.StatusCode.UNAVAILABLE,
59-
})
55+
_TRANSIENT_GRPC_CODES = frozenset(
56+
{
57+
grpc.StatusCode.CANCELLED,
58+
grpc.StatusCode.UNAVAILABLE,
59+
}
60+
)
6061
_SCHEDULE_RETRY_INTERVAL_SECONDS = 0.5
6162

6263

@@ -247,14 +248,10 @@ def connect(self, mcpserver_name: str) -> None:
247248
except Exception as exc: # noqa: BLE001 — classified by helper
248249
if not _is_transient_schedule_error(exc):
249250
raise
250-
sleep_for = min(
251-
_SCHEDULE_RETRY_INTERVAL_SECONDS, deadline - time.monotonic()
252-
)
251+
sleep_for = min(_SCHEDULE_RETRY_INTERVAL_SECONDS, deadline - time.monotonic())
253252
if sleep_for <= 0:
254253
raise
255-
logger.debug(
256-
'schedule_new_workflow returned transient error %s; retrying', exc
257-
)
254+
logger.debug('schedule_new_workflow returned transient error %s; retrying', exc)
258255
time.sleep(sleep_for)
259256

260257
remaining = deadline - time.monotonic()

ext/dapr-ext-workflow/tests/test_mcp_client.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from unittest.mock import AsyncMock, MagicMock, patch
2020

2121
import grpc
22-
2322
from dapr.ext.workflow._durabletask import client
2423
from dapr.ext.workflow.aio.mcp import DaprMCPClient as AioDaprMCPClient
2524
from dapr.ext.workflow.mcp import MCP_WORKFLOW_PREFIX, DaprMCPClient, MCPToolDef
@@ -440,9 +439,7 @@ def test_retries_on_unavailable(self):
440439
def test_non_transient_propagates_immediately(self):
441440
"""A non-CANCELLED/UNAVAILABLE error must not be retried."""
442441
mock_wf = MagicMock()
443-
mock_wf.schedule_new_workflow.side_effect = _StubRpcError(
444-
grpc.StatusCode.PERMISSION_DENIED
445-
)
442+
mock_wf.schedule_new_workflow.side_effect = _StubRpcError(grpc.StatusCode.PERMISSION_DENIED)
446443

447444
mcp_client = DaprMCPClient(timeout_in_seconds=30, wf_client=mock_wf)
448445
with patch('dapr.ext.workflow.mcp.time.sleep') as sleep_mock:
@@ -455,16 +452,17 @@ def test_non_transient_propagates_immediately(self):
455452
def test_deadline_exhausted_raises_last_error(self):
456453
"""When the timeout budget runs out mid-retry, propagate the last error."""
457454
mock_wf = MagicMock()
458-
mock_wf.schedule_new_workflow.side_effect = _StubRpcError(
459-
grpc.StatusCode.CANCELLED
460-
)
455+
mock_wf.schedule_new_workflow.side_effect = _StubRpcError(grpc.StatusCode.CANCELLED)
461456

462457
mcp_client = DaprMCPClient(timeout_in_seconds=1, wf_client=mock_wf)
463458
# Patch monotonic to advance past the deadline immediately so we don't
464459
# actually sleep for a second in tests.
465-
with patch('dapr.ext.workflow.mcp.time.sleep'), patch(
466-
'dapr.ext.workflow.mcp.time.monotonic',
467-
side_effect=[0.0, 2.0],
460+
with (
461+
patch('dapr.ext.workflow.mcp.time.sleep'),
462+
patch(
463+
'dapr.ext.workflow.mcp.time.monotonic',
464+
side_effect=[0.0, 2.0],
465+
),
468466
):
469467
with self.assertRaises(grpc.RpcError):
470468
mcp_client.connect('weather')
@@ -482,9 +480,12 @@ def test_budget_exhausted_after_schedule_succeeds(self):
482480
mcp_client = DaprMCPClient(timeout_in_seconds=1, wf_client=mock_wf)
483481
# monotonic: 0.0 → deadline = 1.0; 0.4 → sleep_for = 0.5 (still in budget);
484482
# 2.0 → post-loop remaining = -1.0 → raise.
485-
with patch('dapr.ext.workflow.mcp.time.sleep'), patch(
486-
'dapr.ext.workflow.mcp.time.monotonic',
487-
side_effect=[0.0, 0.4, 2.0],
483+
with (
484+
patch('dapr.ext.workflow.mcp.time.sleep'),
485+
patch(
486+
'dapr.ext.workflow.mcp.time.monotonic',
487+
side_effect=[0.0, 0.4, 2.0],
488+
),
488489
):
489490
with self.assertRaises(RuntimeError) as ctx:
490491
mcp_client.connect('weather')
@@ -514,14 +515,15 @@ async def test_retries_then_succeeds_on_cancelled(self):
514515

515516
async def test_deadline_exhausted_raises(self):
516517
mock_wf = AsyncMock()
517-
mock_wf.schedule_new_workflow.side_effect = _StubRpcError(
518-
grpc.StatusCode.CANCELLED
519-
)
518+
mock_wf.schedule_new_workflow.side_effect = _StubRpcError(grpc.StatusCode.CANCELLED)
520519

521520
mcp_client = AioDaprMCPClient(timeout_in_seconds=1, wf_client=mock_wf)
522-
with patch('dapr.ext.workflow.aio.mcp.asyncio.sleep', new=AsyncMock()), patch(
523-
'dapr.ext.workflow.aio.mcp.time.monotonic',
524-
side_effect=[0.0, 2.0],
521+
with (
522+
patch('dapr.ext.workflow.aio.mcp.asyncio.sleep', new=AsyncMock()),
523+
patch(
524+
'dapr.ext.workflow.aio.mcp.time.monotonic',
525+
side_effect=[0.0, 2.0],
526+
),
525527
):
526528
with self.assertRaises(grpc.RpcError):
527529
await mcp_client.connect('weather')
@@ -535,9 +537,12 @@ async def test_budget_exhausted_after_schedule_succeeds(self):
535537
]
536538

537539
mcp_client = AioDaprMCPClient(timeout_in_seconds=1, wf_client=mock_wf)
538-
with patch('dapr.ext.workflow.aio.mcp.asyncio.sleep', new=AsyncMock()), patch(
539-
'dapr.ext.workflow.aio.mcp.time.monotonic',
540-
side_effect=[0.0, 0.4, 2.0],
540+
with (
541+
patch('dapr.ext.workflow.aio.mcp.asyncio.sleep', new=AsyncMock()),
542+
patch(
543+
'dapr.ext.workflow.aio.mcp.time.monotonic',
544+
side_effect=[0.0, 0.4, 2.0],
545+
),
541546
):
542547
with self.assertRaises(RuntimeError) as ctx:
543548
await mcp_client.connect('weather')

0 commit comments

Comments
 (0)