dotenv run --no-override expands variables with the wrong precedence
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với đường dẫn CLI run được mô tả trong issue, nơi dotenv_values() mở rộng các biến trước khi các khóa môi trường được lọc. Chạy bản tái hiện được cung cấp và xác minh rằng cả DOTENV_TEST_BASE và DOTENV_TEST_DERIVED đều sử dụng giá trị môi trường hiện có, kể cả khi giá trị đó rỗng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 8.9k
- Fork
- 581
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của theskumar/python-dotenv
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
theskumar/python-dotenv#699 · 1 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 28/100
theskumar/python-dotenv#693 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
theskumar/python-dotenv#683 · 4 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
theskumar/python-dotenv#644 · 2 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
theskumar/python-dotenv#631 · 3 bình luận · 1 reaction ·
Tất cả issue của theskumar/python-dotenv
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenHands/extensions#626 · 1 bình luận ·
-
Change observation tooltip text Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
CSCfi/sd-search-api#39 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
please add to porn list Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
StevenBlack/hosts#3255 ·