Skip to content

Commit 8fa461e

Browse files
committed
Fix CLI 'get' command treating empty values as missing
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.
1 parent 09d7cee commit 8fa461e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/dotenv/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def get(ctx: click.Context, key: Any) -> None:
136136
values = dotenv_values(stream=stream)
137137

138138
stored_value = values.get(key)
139-
if stored_value:
139+
if stored_value is not None:
140140
click.echo(stored_value)
141141
else:
142142
sys.exit(1)

0 commit comments

Comments
 (0)