Variable declared without a value suppresses ${VAR:-default} expansion
Mantenedores costumam responder em até 12 dias
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 85/100
Direção de pesquisa
A issue aponta Variable.resolve() em src/dotenv/variables.py e apresenta uma reprodução mínima com dotenv_values(). Leia primeiro esse método e os testes de expansão de variáveis; em seguida, verifique como um valor None é tratado para ${A} e ${A:-fallback}. O resultado esperado é que a forma com valor padrão use esse valor, enquanto ${A} continue sendo expandido para uma string vazia.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 8.9k
- Forks
- 618
- Merge médio
- 12d 6min
- PRs com merge (30d)
- 3
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de theskumar/python-dotenv
-
An empty value ignores ${name:-default}Talvez já em andamento @SashaMIT assumiu há 41 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
theskumar/python-dotenv#715 ·
Mantenedores costumam responder em até 12 dias
-
set_key and unset_key don't fsync before replacing the .env fileTalvez já em andamento @Imkkey assumiu há 40 dias. Abertaenhancement
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
theskumar/python-dotenv#713 ·
Mantenedores costumam responder em até 12 dias
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 28/100
theskumar/python-dotenv#693 · 1 comentário ·
Mantenedores costumam responder em até 12 dias
-
python-dotenv installation without cli masks python-dotenv cliTalvez já em andamento @gyanu2507 assumiu há 80 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
theskumar/python-dotenv#683 · 4 comentários ·
Mantenedores costumam responder em até 12 dias
-
Feature Request: Automatically copy `default.env` to `.env`Talvez já em andamento @dradetsky assumiu há 189 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
theskumar/python-dotenv#644 · 2 comentários ·
Mantenedores costumam responder em até 12 dias
Todas as issues de theskumar/python-dotenv
Issues semelhantes
-
[Bug]: graphify query loads every language extractor just for _file_stem (about 34 ms per call)Talvez já em andamento @rohit-jsfreaky assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Graphify-Labs/graphify#5160 · 1 comentário ·
Mantenedores costumam responder em até 2 dias
-
Minor bug: Main page buttonAbertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
-
Operations on a list[T] | None var throw when the value is NoneTalvez já em andamento @masenf assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
reflex-dev/reflex#7826 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
UKGovernmentBEIS/control-arena#947 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
jasonacox/Powerwall-Dashboard#897 · 1 comentário ·
Mantenedores costumam responder em até 1 dia