Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dapr/ext/workflow/_durabletask/aio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,13 @@ async def raise_orchestration_event_with_result(
app_id: Optional[str] = None,
) -> pb.RaiseEventResponse:
"""Like raise_orchestration_event, but returns the sidecar's response."""
input_pb = (
wrappers_pb2.StringValue(value=shared.to_json(data)) if data is not None else None
)
req = pb.RaiseEventRequest(
instanceId=instance_id,
name=event_name,
input=wrappers_pb2.StringValue(value=shared.to_json(data)) if data else None,
input=input_pb,
router=new_task_router(app_id),
)

Expand Down
5 changes: 4 additions & 1 deletion dapr/ext/workflow/_durabletask/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,13 @@ def raise_orchestration_event_with_result(
app_id: Optional[str] = None,
) -> pb.RaiseEventResponse:
"""Like raise_orchestration_event, but returns the sidecar's response."""
input_pb = (
wrappers_pb2.StringValue(value=shared.to_json(data)) if data is not None else None
)
req = pb.RaiseEventRequest(
instanceId=instance_id,
name=event_name,
input=wrappers_pb2.StringValue(value=shared.to_json(data)) if data else None,
input=input_pb,
router=new_task_router(app_id),
)

Expand Down
30 changes: 30 additions & 0 deletions tests/ext/workflow/durabletask/test_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import json
from unittest.mock import MagicMock, patch

import pytest

from dapr.ext.workflow._durabletask import client
from dapr.ext.workflow._durabletask.internal.grpc_interceptor import DefaultClientInterceptorImpl
from dapr.ext.workflow._durabletask.internal.shared import (
Expand Down Expand Up @@ -175,3 +178,30 @@ def test_taskhub_client_close_closes_channel_handles_exceptions():
task_hub_client = client.TaskHubGrpcClient()
task_hub_client.close()
mock_channel.close.assert_called_once()


@pytest.mark.parametrize(
'data', [False, 0, '', [], {}], ids=['false', 'zero', 'empty_str', 'empty_list', 'empty_dict']
)
def test_raise_orchestration_event_sends_falsy_data(data):
"""A falsy payload such as False or 0 must reach the workflow, not arrive as None."""
with patch('dapr.ext.workflow._durabletask.internal.shared.get_grpc_channel'):
task_hub_client = client.TaskHubGrpcClient()
task_hub_client._stub = MagicMock()

task_hub_client.raise_orchestration_event('instance1', 'approval', data=data)

req = task_hub_client._stub.RaiseEvent.call_args[0][0]
assert req.HasField('input')
assert req.input.value == json.dumps(data)


def test_raise_orchestration_event_without_data_sends_no_input():
with patch('dapr.ext.workflow._durabletask.internal.shared.get_grpc_channel'):
task_hub_client = client.TaskHubGrpcClient()
task_hub_client._stub = MagicMock()

task_hub_client.raise_orchestration_event('instance1', 'approval')

req = task_hub_client._stub.RaiseEvent.call_args[0][0]
assert not req.HasField('input')
28 changes: 27 additions & 1 deletion tests/ext/workflow/durabletask/test_client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
# limitations under the License.

import asyncio
from unittest.mock import Mock, patch
import json
from unittest.mock import AsyncMock, Mock, patch

import grpc
import pytest
Expand Down Expand Up @@ -258,3 +259,28 @@ async def cancel_immediately(*args, **kwargs):
with pytest.raises(grpc.RpcError) as exc_info:
await client.wait_for_orchestration_completion('test-instance', timeout=300)
assert not isinstance(exc_info.value, TimeoutError)


@pytest.mark.parametrize(
'data', [False, 0, '', [], {}], ids=['false', 'zero', 'empty_str', 'empty_list', 'empty_dict']
)
async def test_raise_orchestration_event_sends_falsy_data(data):
"""The async client must also send a falsy payload instead of dropping it."""
client = AsyncTaskHubGrpcClient()
client._stub = AsyncMock()

await client.raise_orchestration_event('instance1', 'approval', data=data)

req = client._stub.RaiseEvent.call_args[0][0]
assert req.HasField('input')
assert req.input.value == json.dumps(data)


async def test_raise_orchestration_event_without_data_sends_no_input():
client = AsyncTaskHubGrpcClient()
client._stub = AsyncMock()

await client.raise_orchestration_event('instance1', 'approval')

req = client._stub.RaiseEvent.call_args[0][0]
assert not req.HasField('input')