Skip to content

Comments

Fix CLI 'get' command treating empty-string values as missing#619

Open
bysiber wants to merge 1 commit intotheskumar:mainfrom
bysiber:fix/cli-get-empty-value
Open

Fix CLI 'get' command treating empty-string values as missing#619
bysiber wants to merge 1 commit intotheskumar:mainfrom
bysiber:fix/cli-get-empty-value

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 20, 2026

The get CLI command uses a truthiness check (if stored_value:) to determine whether a key was found. This fails for empty-string values, since bool("") is False.

For example, given a .env file with:

DATABASE_PREFIX=
EMPTY_VAR=""

Running dotenv get DATABASE_PREFIX exits with code 1, as if the key doesn't exist — but it does exist, it's just set to an empty string.

The fix changes the check from if stored_value: to if stored_value is not None:, which correctly distinguishes between a key with an empty value and a key that is genuinely absent.

The 'get' command uses 'if stored_value:' to check whether a key
exists. This is a truthiness check that evaluates to False for empty
strings, so 'KEY=' or 'KEY=""' causes the command to exit with
code 1 as if the key doesn't exist.

Use 'is not None' instead to correctly distinguish between a key
set to an empty string and a key that is not present.
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.

1 participant