DAPR_* environment variables are snapshotted at import time, so loading config after import silently dials localhost
維護者通常 7 天內回覆
評估
研究方向
Start with the dapr.conf settings module, which reads the DAPR_* variables at import, and with dapr.conf.helpers.GrpcEndpoint, which builds the endpoint from them. Run the reproduction in the issue to confirm the value stays None after os.environ changes. Done means either the settings are read when a client is constructed, or a clear error or warning is raised when os.environ and the snapshot disagree. The issue leaves the choice between these options to the maintainers, so confirm the approach before writing code.
由索引模型根據 Issue 內容生成。
描述
What happens
dapr.conf.settings reads the DAPR_* environment variables when the module is
first imported. Setting them afterwards has no effect, and the SDK silently
falls back to dns:localhost:50001 instead of the configured endpoint. There is
no warning and no error — the first symptom is a connection failure that looks
like a network or platform problem.
This is easy to hit with any of the common config patterns: python-dotenv in a
config.py, a settings module, a CLI that parses args before wiring the client,
or a framework that imports your package before your .env loader runs.
Reproduction
import os
assert "DAPR_GRPC_ENDPOINT" not in os.environ
import dapr.conf as conf
print(conf.settings.DAPR_GRPC_ENDPOINT) # None
os.environ["DAPR_GRPC_ENDPOINT"] = "https://grpc-example.example.com:443"
print(os.environ["DAPR_GRPC_ENDPOINT"]) # the value we just set
print(conf.settings.DAPR_GRPC_ENDPOINT) # None <-- still
from dapr.conf.helpers import GrpcEndpoint
ep = GrpcEndpoint(conf.settings.DAPR_GRPC_ENDPOINT
or f"localhost:{conf.settings.DAPR_GRPC_PORT}")
print(ep.endpoint) # dns:localhost:50001
Observed output:
1. imported dapr.conf with no DAPR_GRPC_ENDPOINT set
settings.DAPR_GRPC_ENDPOINT = None
settings.DAPR_GRPC_PORT = 50001
2. set DAPR_GRPC_ENDPOINT AFTER import
os.environ value = https://grpc-example.example.com:443
settings.DAPR_GRPC_ENDPOINT = None
3. endpoint the SDK would dial: dns:localhost:50001
Expected
Any of the following would have saved the debugging time:
- Read the setting lazily, at client construction, rather than at import.
- Keep the import-time read, but re-check
os.environwhen a client is built
and raise or warn on a mismatch betweenos.environ["DAPR_GRPC_ENDPOINT"]
andsettings.DAPR_GRPC_ENDPOINT. - Document it prominently in the client docs — "set
DAPR_*before importing
dapr" — since the current failure mode is silent.
(1) seems best; (2) is the cheapest thing that makes the failure loud.
Environment
dapr1.18.3,dapr-ext-workflow1.18.3- Python 3.12.12, macOS 15 (darwin 24.3.0)
- Talking to a managed Dapr control plane over a remote gRPC endpoint, so the
localhost fallback can never succeed
Why it matters
Against a local sidecar the fallback is often correct, which is why this is
rarely noticed. Against any remote or managed endpoint it is always wrong, and
the error surfaces far from its cause — the one I chased presented as "every
connection fails", with correct-looking values in .env and in os.environ.
- 主要語言
- Python
- 星號
- 274
- 分支
- 157
- 平均合併
- 8 天 20 小時
- 30 天內合併 PR
- 31
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
dapr/python-sdk 的其他 Issue
-
Report the http(s):// gRPC endpoint deprecation as a DeprecationWarning, not a UserWarning on every client可能已有人在做 @kocaemre 今天認領。 未關閉good first issue
難度 2/5 1-3 小時 新手友好度 85/100
dapr/python-sdk#1275 ·
維護者通常 7 天內回覆
-
SDK Alignment of Workflow Examples可能重新可做 關聯的 PR 已關閉且未合併。 未關閉dapr-ext-workflow good first issue kind/enhancement P2
難度 2/5 1-2 天 新手友好度 72/100
dapr/python-sdk#853 · 4 則留言 ·
維護者通常 7 天內回覆
-
dapr-ext-workflow kind/enhancement
難度 4/5 3-5 天 新手友好度 55/100
dapr/python-sdk#1246 ·
維護者通常 7 天內回覆
-
[BUG] subscribe_with_handler stops silently: async task can die or be collected, sync retry path exits, handler errors reconnect the stream可能已有人在做 @CasperGN 於 19 天前認領。 未關閉kind/bug
難度 4/5 3-5 天 新手友好度 65/100
dapr/python-sdk#1233 ·
維護者通常 7 天內回覆
-
[BUG] Configuration subscription stops permanently after the daprd sidecar restarts可能已有人在做 @CasperGN 於 16 天前認領。 未關閉kind/bug
難度 4/5 3-5 天 新手友好度 68/100
dapr/python-sdk#1232 ·
維護者通常 7 天內回覆
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 68/100
Deltares/imod-python#1940 ·
維護者通常 1 天內回覆
-
effort: low prio: low ready
難度 1/5 1 小時以內 新手友好度 82/100
digitalfabrik/integreat-cms#4621 ·
維護者通常 5 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
ioos/compliance-checker#1375 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
netbox status: backlog topic: testing type: housekeeping
難度 2/5 1-3 小時 新手友好度 70/100
netbox-community/netbox#23395 ·
維護者通常 1 天內回覆