Variable declared without a value suppresses ${VAR:-default} expansion
维护者通常 12 天内回复
评估
调研方向
Issue 指出了 src/dotenv/variables.py 中的 Variable.resolve(),并提供了使用 dotenv_values() 的最小复现示例。先阅读该方法和变量展开测试,然后检查 ${A} 和 ${A:-fallback} 对 None 值的处理方式。完成标准是:带默认值的形式使用默认值,而普通的 ${A} 仍展开为空字符串。
由索引模型根据 Issue 内容生成。
描述
Environment
- python-dotenv 1.2.4 (main, commit 4fbc6ff)
- Python 3.14.0 on Windows 11; the code involved is platform independent
Minimal repro
import io
from dotenv import dotenv_values
print(dotenv_values(stream=io.StringIO("A\nB=${A:-fallback}")))
Actual
OrderedDict({'A': None, 'B': ''})
Expected
OrderedDict({'A': None, 'B': 'fallback'})
${A} should still expand to ""; only the defaulted form is affected.
Why this is wrong
The README's "Variable expansion" section lists the resolution order for
dotenv_values() as: value of the variable in the .env file, value in the
environment, default value, then empty string. A key written without a value
(A) is documented earlier as producing None, and load_dotenv is said to
"simply ignore such variables" — that is, the variable is unset, not set to the
empty string. Since the default is only skipped when the variable has a value,
${A:-fallback} should produce fallback here.
This also contradicts the explicit distinction the README draws between FOO
and FOO=: A and A= currently expand identically ("") even though only
A= is the empty string.
The cause is in Variable.resolve() (src/dotenv/variables.py): a name that is
present in the mapping with a None value is converted to "", so the
supplied default is never used.
- 主要语言
- Python
- 星标
- 8.9k
- 派生
- 618
- 平均合并
- 12 天 6 分钟
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
theskumar/python-dotenv 的其他 Issue
-
An empty value ignores ${name:-default}可能已有人在做 @SashaMIT 于 41 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
theskumar/python-dotenv#715 ·
维护者通常 12 天内回复
-
set_key and unset_key don't fsync before replacing the .env file可能已有人在做 @Imkkey 于 40 天前认领。 未关闭enhancement
难度 3/5 1-2 天 新手友好度 72/100
theskumar/python-dotenv#713 ·
维护者通常 12 天内回复
-
难度 5/5 一周以上 新手友好度 28/100
theskumar/python-dotenv#693 · 1 条评论 ·
维护者通常 12 天内回复
-
python-dotenv installation without cli masks python-dotenv cli可能已有人在做 @gyanu2507 于 80 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
theskumar/python-dotenv#683 · 4 条评论 ·
维护者通常 12 天内回复
-
Feature Request: Automatically copy `default.env` to `.env`可能已有人在做 @dradetsky 于 189 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
theskumar/python-dotenv#644 · 2 条评论 ·
维护者通常 12 天内回复
查看 theskumar/python-dotenv 的全部 Issue
相似的 Issue
-
[Bug]: graphify query loads every language extractor just for _file_stem (about 34 ms per call)可能已有人在做 @rohit-jsfreaky 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
Graphify-Labs/graphify#5160 · 1 条评论 ·
维护者通常 2 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
-
Operations on a list[T] | None var throw when the value is None可能已有人在做 @masenf 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
reflex-dev/reflex#7826 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
UKGovernmentBEIS/control-arena#947 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
jasonacox/Powerwall-Dashboard#897 · 1 条评论 ·
维护者通常 1 天内回复