dotenv get exits with code 1 for empty string values
まだ誰も着手していません。
評価
調査の方向性
src/dotenv/cli.py の dotenv get コマンドから始め、存在しないキーと空の値をどのように区別しているかを確認します。レポートにある Python subprocess の例で問題を再現してください。既存の空の値が空文字列を出力してコード 0 で終了し、存在しないキーは引き続きコード 1 で終了すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
dotenv get KEY treats an empty string value as missing because the CLI uses a truthiness check (if stored_value:) instead of testing for key presence / None.
Empty values are valid in .env files (KEY= or KEY=""). The library API already returns them correctly via get_key / dotenv_values; only the CLI get command is wrong.
Steps to reproduce
import subprocess, sys, tempfile
from pathlib import Path
from dotenv import set_key
with tempfile.TemporaryDirectory() as directory:
path = Path(directory) / ".env"
set_key(path, "EMPTY", "")
result = subprocess.run(
[sys.executable, "-m", "dotenv", "-f", str(path), "get", "EMPTY"],
capture_output=True,
text=True,
)
print(result.returncode, repr(result.stdout))
Expected behavior
0 ''
(exit code 0, empty value printed)
Actual behavior
1 ''
(exit code 1 — same as a missing key)
dotenv get ZERO with ZERO=0 works (exit 0), so only falsy-but-present empty strings are affected.
Environment
- python-dotenv: 1.2.3 (current
main) - Python: 3.14
- OS: Windows
Suggested fix
In src/dotenv/cli.py get, distinguish missing/None from an empty string, e.g. exit only when the key is absent or the stored value is None.
- 主要言語
- Python
- スター
- 8.9k
- フォーク
- 581
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
theskumar/python-dotenv のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
theskumar/python-dotenv#697 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 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 件 ·
theskumar/python-dotenv の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
OpenHands/extensions#626 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
CSCfi/sd-search-api#39 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
StevenBlack/hosts#3255 ·