theskumar / theskumar/python-dotenv

dotenv get exits with code 1 for empty string values

Aperta Adatta ai principianti
#699 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
8.9k
Fork
581
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Description

dotenv get KEY treats an empty string value as missing because the CLI uses a truthiness check (if stored_value:) instead of testing for key presence / None.

Empty values are valid in .env files (KEY= or KEY=""). The library API already returns them correctly via get_key / dotenv_values; only the CLI get command is wrong.

Steps to reproduce

import subprocess, sys, tempfile
from pathlib import Path
from dotenv import set_key

with tempfile.TemporaryDirectory() as directory:
    path = Path(directory) / ".env"
    set_key(path, "EMPTY", "")
    result = subprocess.run(
        [sys.executable, "-m", "dotenv", "-f", str(path), "get", "EMPTY"],
        capture_output=True,
        text=True,
    )
    print(result.returncode, repr(result.stdout))

Expected behavior

0 ''

(exit code 0, empty value printed)

Actual behavior

1 ''

(exit code 1 — same as a missing key)

dotenv get ZERO with ZERO=0 works (exit 0), so only falsy-but-present empty strings are affected.

Environment

  • python-dotenv: 1.2.3 (current main)
  • Python: 3.14
  • OS: Windows

Suggested fix

In src/dotenv/cli.py get, distinguish missing/None from an empty string, e.g. exit only when the key is absent or the stored value is None.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in src/dotenv/cli.py, nel comando dotenv get, e verifica come distingue una chiave mancante da un valore vuoto. Riproduci il problema con l’esempio Python subprocess nel report; il lavoro è terminato quando un valore vuoto esistente stampa una stringa vuota ed esce con il codice 0, mentre una chiave mancante continua a uscire con il codice 1.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
cli
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Attiva
Chiarezza
Specificata chiaramente
Idoneità per principianti
88/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.