dotenv get exits with code 1 for empty string values
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
Research direction
Start in src/dotenv/cli.py at the dotenv get command and inspect how it distinguishes a missing key from an empty value. Reproduce the issue with the Python subprocess example in the report; done means an existing empty value prints an empty string and exits with code 0, while a missing key still exits with code 1.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 8.9k
- Forks
- 581
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from theskumar/python-dotenv
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
theskumar/python-dotenv#697 ·
-
Difficulty 5/5 Over a week Newbie friendliness 28/100
theskumar/python-dotenv#693 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
theskumar/python-dotenv#683 · 4 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
theskumar/python-dotenv#644 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
theskumar/python-dotenv#631 · 3 comments · 1 reaction ·
All issues in theskumar/python-dotenv
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100