microsoft / microsoft/durabletask-python
[azure-functions-durable] Orchestrator context parameter name is fixed to `context`, blocking access to `func.Context`
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 40
- 分支
- 33
- 平均合併
- 2 天 2 小時
- 30 天內合併 PR
- 6
描述
Summary
In the azure-functions-durable (V2) package, the parameter that receives the
orchestration context is effectively hardcoded to the name context. As a
consequence:
- A user-supplied
context_nameother than"context"on
@app.orchestration_trigger(...)does not work — the host cannot bind the
trigger to the generated handle. - There is no way for an orchestrator to also receive an
azure.functions.Context(func.Context) parameter, because the Functions
host injectsfunc.Contextonly into a parameter named exactlycontext
that is not a trigger binding — and that name is always consumed by the
orchestrationTrigger binding.
This matches V1 behavior (see "Not a regression" below), so it is not a
regression introduced by V2. Filing this to track it as a potential V2
improvement to be considered after the Functions PR merges and the beta
release ships.
Mechanism / relevant code paths
The Azure Functions host binds a trigger to a function parameter by name,
and it inspects the generated handle (not the user's function).
-
The trigger binding is registered with
name=context_name:azure/durable_functions/decorators/durable_app.py—
orchestration_trigger(context_name, ...)calls
OrchestrationTrigger(name=context_name, ...).
-
The generated handle that the host actually indexes hardcodes a parameter
literally namedcontext:azure/durable_functions/orchestrator.py—Orchestrator.create:def handle(context: func.OrchestrationContext) -> str: return Orchestrator(fn).handle(context)- The parameter must be annotated
azure.functions.OrchestrationContext
for the host's orchestrationTrigger binding converter to accept it.
-
Because the host matches the binding
name(context_name) to a parameter
ofhandleby name, they only line up whencontext_name == "context".
Any othercontext_nameleaves the trigger unbound. -
func.Contextinjection: the Python worker injectsfunc.Contextonly into
a parameter named exactlycontextthat is not itself a trigger binding.
Since the orchestrationTrigger always occupies thecontextname, there is
no freecontextparameter forfunc.Contextto be injected into. -
Separately, durabletask's executor invokes the user's orchestrator as
fn(ctx, input)— there is no slot in that calling convention for a
func.Contextobject to be passed through to user code.
Not a regression (V1 parity)
V1 has the same structural constraint. In
azure-functions-durable-python's azure/durable_functions/orchestrator.py,
Orchestrator.create also registers a single-parameter
def handle(context: func.OrchestrationContext), so a V1 orchestrator could
never receive a working func.Context parameter either. V2 preserves this
behavior.
Related parity gap: function_context contents
The V1-compat DurableOrchestrationContext adapter currently exposes an empty
function_context. V1's function_context is not necessarily empty: in
azure/durable_functions/models/DurableOrchestrationContext.py, __init__
consumes a fixed set of named fields (history, instanceId, isReplaying,
parentInstanceId, input, upperSchemaVersion, maximumShortTimerDuration,
longRunningTimerIntervalDuration, upperSchemaVersionNew) and funnels every
remaining field of the orchestration-trigger JSON into
FunctionContext(**kwargs). As of today the WebJobs extension injects at least
one such field — defaultHttpAsyncRequestSleepTimeMillseconds (observed value
30000, the durable-HTTP async polling interval) — so a live V1
function_context carries that value.
V2 receives the orchestration input via a protobuf trigger that does not carry
these arbitrary extra fields, so the compat adapter has no source to populate
function_context from. This is a minor parity gap to consider alongside the
context-name / func.Context work above.
Notes
- Out of scope for the current parity-focused Functions PR; capturing here so
it can be picked up as a V2 improvement after the beta release.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 azure/durable_functions/decorators/durable_app.py 和 azure/durable_functions/orchestrator.py 開始,尤其查看 orchestration_trigger 和 Orchestrator.create。追蹤產生的 handle 如何建立索引,以及 durabletask 如何呼叫使用者函式;接著檢視 V1 相容性介面卡,以及 DurableOrchestrationContext 對 function_context 的處理。完成這項工作需要針對自訂內容名稱、對 func.Context 的存取,以及相關的 function_context 對等性缺口,取得一致同意的 V2 方案。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- azure, python
- 領域
- backend
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100