Skip to content

Commit 2c7d5b2

Browse files
committed
Return an emtpy function context instead of raising
1 parent 16f3cf1 commit 2c7d5b2

3 files changed

Lines changed: 43 additions & 10 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
from typing import Any
5+
6+
7+
class FunctionContext:
8+
"""Holds additional function-level attributes not used by Durable.
9+
10+
Backwards-compatible with the v1 ``FunctionContext``, which was populated
11+
from any *extra* fields present in the orchestration-trigger JSON payload
12+
beyond those the ``DurableOrchestrationContext`` consumed directly.
13+
14+
In v2 the orchestration request is a protobuf that carries no such arbitrary
15+
extra fields, so this is typically empty -- matching the common v1 case,
16+
where the base trigger payload (``instanceId``, ``parentInstanceId``,
17+
``isReplaying``, ``input``, ``upperSchemaVersion``, ``history``) is fully
18+
consumed and nothing is left over.
19+
"""
20+
21+
def __init__(self, **kwargs: Any) -> None:
22+
for key, value in kwargs.items():
23+
setattr(self, key, value)

azure-functions-durable/azure/durable_functions/internal/compat/orchestration_context.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from durabletask.task import OrchestrationContext, RetryPolicy, Task
1212

1313
from ..serialization import DEFAULT_FUNCTIONS_DATA_CONVERTER
14+
from .function_context import FunctionContext
1415
from .token_source import TokenSource
1516

1617

@@ -34,6 +35,10 @@ def __init__(self,
3435
self._input_type = input_type
3536
self._custom_status: Any = None
3637
self._will_continue_as_new = False
38+
# v1 exposed a FunctionContext bag of any extra trigger-payload fields.
39+
# The durabletask protobuf request carries no such extras, so this is
40+
# an empty bag -- matching the common v1 runtime case.
41+
self._function_context = FunctionContext()
3742

3843
# -- input ---------------------------------------------------------------
3944
def get_input(self, expected_type: Optional[type] = None) -> Any:
@@ -96,14 +101,16 @@ def parent_instance_id(self) -> Optional[str]:
96101
return self._ctx.parent_instance_id
97102

98103
@property
99-
def function_context(self) -> Any:
100-
"""Get the Azure Functions-level context.
101-
102-
Not available: durabletask does not provide the v1 ``FunctionContext``
103-
binding metadata.
104+
def function_context(self) -> FunctionContext:
105+
"""Get the Azure Functions-level context (extra trigger-payload fields).
106+
107+
Returned as an (empty) :class:`FunctionContext` for v1 drop-in
108+
compatibility. The durabletask orchestration request does not carry the
109+
arbitrary extra fields the v1 JSON trigger payload could, so there is
110+
nothing to populate -- which matches the common v1 case where the base
111+
payload is fully consumed and the bag is empty.
104112
"""
105-
raise NotImplementedError(
106-
"function_context is not available in this SDK.")
113+
return self._function_context
107114

108115
@property
109116
def histories(self) -> Any:

tests/azure-functions-durable/test_orchestration_context_compat.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,13 @@ def test_parent_instance_id_delegates():
142142
assert adapter.parent_instance_id == "parent-123"
143143

144144

145-
def test_function_context_raises_not_implemented():
145+
def test_function_context_returns_empty_bag():
146+
from azure.durable_functions.internal.compat.function_context import FunctionContext
146147
adapter, _ = _adapter()
147-
with pytest.raises(NotImplementedError):
148-
_ = adapter.function_context
148+
fc = adapter.function_context
149+
assert isinstance(fc, FunctionContext)
150+
# Empty by default: no extra attributes, matching the common v1 case.
151+
assert [a for a in vars(fc)] == []
149152

150153

151154
def test_histories_raises_not_implemented():

0 commit comments

Comments
 (0)