Variable declared without a value suppresses ${VAR:-default} expansion
Maintainer thường phản hồi trong vòng 12 ngà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
- 85/100
Hướng nghiên cứu
Issue chỉ ra Variable.resolve() trong src/dotenv/variables.py và đưa ra một ví dụ tái hiện tối thiểu bằng dotenv_values(). Trước tiên, hãy đọc phương thức đó và các bài kiểm thử mở rộng biến, sau đó kiểm tra giá trị None được xử lý như thế nào với ${A} và ${A:-fallback}. Kết quả cần đạt là dạng có giá trị mặc định sử dụng giá trị đó, còn ${A} vẫn được mở rộng thành chuỗi rỗng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 8.9k
- Fork
- 618
- Merge trung bình
- 12 ngày 6 phút
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc 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
-
An empty value ignores ${name:-default}Có thể đã có người làm @SashaMIT đã nhận 41 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
theskumar/python-dotenv#715 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
set_key and unset_key don't fsync before replacing the .env fileCó thể đã có người làm @Imkkey đã nhận 40 ngày trước. Đang mởenhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
theskumar/python-dotenv#713 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Độ 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 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
python-dotenv installation without cli masks python-dotenv cliCó thể đã có người làm @gyanu2507 đã nhận 80 ngày trước. Đang mở
Độ 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 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Feature Request: Automatically copy `default.env` to `.env`Có thể đã có người làm @dradetsky đã nhận 189 ngày trước. Đang mở
Độ 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 ·
Maintainer thường phản hồi trong vòng 12 ngày
Tất cả issue của theskumar/python-dotenv
Issue tương tự
-
[Bug]: graphify query loads every language extractor just for _file_stem (about 34 ms per call)Có thể đã có người làm @rohit-jsfreaky đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Graphify-Labs/graphify#5160 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Minor bug: Main page buttonĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Operations on a list[T] | None var throw when the value is NoneCó thể đã có người làm @masenf đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
reflex-dev/reflex#7826 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Upfront audit metrics accept out-of-range budgets and return impossible probabilitiesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
UKGovernmentBEIS/control-arena#947 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
jasonacox/Powerwall-Dashboard#897 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày