Skip to content

Commit 3cf2532

Browse files
committed
Added warning message to message_router decorator
Signed-off-by: Roberto Rodriguez <[email protected]>
1 parent 4e0e7dd commit 3cf2532

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

dapr_agents/workflow/decorators/messaging.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import logging
2+
import warnings
23
from copy import deepcopy
34
from typing import Any, Callable, Optional, get_type_hints
5+
46
from dapr_agents.workflow.utils.core import is_valid_routable_model
57
from dapr_agents.workflow.utils.messaging import extract_message_models
68

79
logger = logging.getLogger(__name__)
810

11+
_MESSAGE_ROUTER_DEPRECATION_MESSAGE = (
12+
"@message_router (legacy version from dapr_agents.workflow.decorators.messaging) "
13+
"is deprecated and will be removed in a future release. "
14+
"Please migrate to the updated decorator in "
15+
"`dapr_agents.workflow.decorators.routers`, which supports "
16+
"Union types, forward references, and explicit Dapr workflow integration."
17+
)
918

1019
def message_router(
1120
func: Optional[Callable[..., Any]] = None,
@@ -16,7 +25,8 @@ def message_router(
1625
broadcast: bool = False,
1726
) -> Callable[[Callable[..., Any]], Callable[..., Any]]:
1827
"""
19-
Decorator for registering message handlers by inspecting type hints on the 'message' argument.
28+
[DEPRECATED] Legacy decorator for registering message handlers by inspecting type hints
29+
on the 'message' argument.
2030
2131
This decorator:
2232
- Extracts the expected message model type from function annotations.
@@ -36,6 +46,13 @@ def message_router(
3646
"""
3747

3848
def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
49+
50+
warnings.warn(
51+
_MESSAGE_ROUTER_DEPRECATION_MESSAGE,
52+
DeprecationWarning,
53+
stacklevel=2,
54+
)
55+
3956
is_workflow = hasattr(f, "_is_workflow")
4057
workflow_name = getattr(f, "_workflow_name", None)
4158

@@ -56,7 +73,8 @@ def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
5673
)
5774

5875
logger.debug(
59-
f"@message_router: '{f.__name__}' => models {[m.__name__ for m in message_models]}"
76+
"@message_router (legacy): '%s' => models %s",
77+
f.__name__, [m.__name__ for m in message_models],
6078
)
6179

6280
# Attach metadata for later registration

0 commit comments

Comments
 (0)