Variable declared without a value suppresses ${VAR:-default} expansion

Đang mở Phù hợp với người mới
#750 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 12 ngày

@Omarinho12345 đang làm issue này rồi.

Từ ngày 11/11/2026.

  • #751 của @Omarinho12345 — đang mở

Đá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
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của theskumar/python-dotenv

Tất cả issue của theskumar/python-dotenv

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.