dotenv get exits with code 1 for empty string values

オープン 初心者向け
#699 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
88/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
cli

調査の方向性

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 はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

theskumar/python-dotenv のほかの issue

theskumar/python-dotenv の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。