dotenv run --no-override expands variables with the wrong precedence
还没有人认领这个 Issue。
评估
调研方向
从 issue 中描述的 CLI run 路径开始,其中 dotenv_values() 会在环境键被筛选之前展开变量。运行提供的复现,并验证 DOTENV_TEST_BASE 和 DOTENV_TEST_DERIVED 都使用现有的环境值,包括该值为空的情况。
由索引模型根据 Issue 内容生成。
描述
Description
With dotenv run --no-override, a variable can keep its value from the environment while another variable referring to it gets the value from .env. This leaves the child process with inconsistent configuration.
Steps to reproduce
With python-dotenv[cli] installed, run:
import os
import subprocess
import sys
import tempfile
from pathlib import Path
with tempfile.TemporaryDirectory() as directory:
path = Path(directory) / ".env"
path.write_text(
"DOTENV_TEST_BASE=file\n"
"DOTENV_TEST_DERIVED=${DOTENV_TEST_BASE}/suffix\n"
)
env = dict(os.environ)
env["DOTENV_TEST_BASE"] = "environment"
env.pop("DOTENV_TEST_DERIVED", None)
subprocess.run(
[
sys.executable, "-m", "dotenv", "-f", str(path),
"run", "--no-override", sys.executable, "-c",
"import os; print(os.environ['DOTENV_TEST_BASE']); "
"print(os.environ['DOTENV_TEST_DERIVED'])",
],
env=env,
check=True,
)
Expected behavior
Both values should use the existing environment variable, as they do with load_dotenv(override=False):
environment
environment/suffix
Actual behavior
environment
file/suffix
An existing empty string also reproduces this: the derived value is file/suffix instead of /suffix.
Environment
Reproduced on Windows with Python 3.13.15 and python-dotenv 1.2.3, from commit a00cb2eed0704cd6d2071b2004c37e95ccc86ee5.
Additional context
This is similar to #282, but affects the CLI. run calls dotenv_values(), which expands variables with override=True, before filtering out keys already in the environment. The fix is in #698.
Prepared with OpenAI Codex assistance.
- 主要语言
- Python
- 星标
- 8.9k
- 派生
- 581
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
theskumar/python-dotenv 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
theskumar/python-dotenv#699 · 1 条评论 ·
-
难度 5/5 一周以上 新手友好度 28/100
theskumar/python-dotenv#693 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 55/100
theskumar/python-dotenv#683 · 4 条评论 ·
-
难度 3/5 1-2 天 新手友好度 55/100
theskumar/python-dotenv#644 · 2 条评论 ·
-
难度 3/5 1-2 天 新手友好度 68/100
theskumar/python-dotenv#631 · 3 条评论 · 1 个 reaction ·
查看 theskumar/python-dotenv 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 86/100
zostera/django-bootstrap4#894 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
use-agent-os/agent-os#3276 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
难度 2/5 1-3 小时 新手友好度 88/100
NousResearch/hermes-agent#117848 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
zilliztech/memsearch#759 ·