python-dotenv icon indicating copy to clipboard operation
python-dotenv copied to clipboard

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

Open bysiber opened this issue 9 months ago • 0 comments

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.

bysiber avatar Feb 20 '26 12:02 bysiber