theskumar / theskumar/python-dotenv
dotenv run --no-override expands variables with the wrong precedence
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 8.9k
- フォーク
- 581
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue で説明されている CLI の run パスから始めます。このパスでは、環境キーがフィルタリングされる前に dotenv_values() が変数を展開します。提供された再現手順を実行し、DOTENV_TEST_BASE と DOTENV_TEST_DERIVED の両方が、既存の環境値を使用することを、値が空の場合も含めて確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- cli
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100