Skip to content

Fix dotenv get exiting with code 1 for empty string values - #700

Open
ShamikOfficial wants to merge 2 commits into
theskumar:mainfrom
ShamikOfficial:fix/cli-get-empty-value
Open

Fix dotenv get exiting with code 1 for empty string values#700
ShamikOfficial wants to merge 2 commits into
theskumar:mainfrom
ShamikOfficial:fix/cli-get-empty-value

Conversation

@ShamikOfficial

Copy link
Copy Markdown

Fixes #699.

Problem

dotenv get KEY uses if stored_value: so an empty string is treated as missing and the command exits with code 1 — the same as an absent key.

>>> from dotenv import set_key, get_key
>>> set_key(".env", "EMPTY", "")
>>> get_key(".env", "EMPTY")   # library API is fine
''
>>> # dotenv get EMPTY  -> exit code 1

Empty values (KEY= / KEY="") are valid; only the CLI was wrong.

Fix

Exit only when the key is absent or the stored value is None (bare key with no value). Empty strings are echoed and exit 0.

Tests

  • New test_get_empty_string_value pins exit code 0 and a blank line of output for a=.
  • Existing get tests still pass.

pytest tests/test_cli.py::test_get_existing_value tests/test_cli.py::test_get_empty_string_value tests/test_cli.py::test_get_non_existent_value — 3 passed.

ShamikOfficial and others added 2 commits September 12, 2026 12:32
Empty KEY= values are valid; the CLI truthiness check treated them as missing.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dotenv get exits with code 1 for empty string values

1 participant