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 天內回覆