Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Fixed

- `dotenv get` no longer exits with code 1 for empty string values (`KEY=`) by [@ShamikOfficial] in [#700]
- An unquoted empty value followed by an inline comment (e.g. `KEY= # comment`) is now parsed as an empty string instead of the comment text by [@Noethix55555] in [#663]

## [1.2.3] - 2026-08-16
Expand Down Expand Up @@ -448,6 +449,7 @@ os.PathLike]` instead of just `os.PathLike` (#347 by [@bbc2]).
[#640]: https://github.com/theskumar/python-dotenv/pull/640
[#663]: https://github.com/theskumar/python-dotenv/pull/663
[#680]: https://github.com/theskumar/python-dotenv/pull/680
[#700]: https://github.com/theskumar/python-dotenv/pull/700
[790c5c0]: https://github.com/theskumar/python-dotenv/commit/790c5c02991100aa1bf41ee5330aca75edc51311

<!-- contributors -->
Expand Down Expand Up @@ -494,6 +496,7 @@ os.PathLike]` instead of just `os.PathLike` (#347 by [@bbc2]).
[@randomseed42]: https://github.com/randomseed42
[@sammck]: https://github.com/sammck
[@samwyma]: https://github.com/samwyma
[@ShamikOfficial]: https://github.com/ShamikOfficial
[@sidharth-sudhir]: https://github.com/sidharth-sudhir
[@snobu]: https://github.com/snobu
[@techalchemy]: https://github.com/techalchemy
Expand Down
7 changes: 3 additions & 4 deletions src/dotenv/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,10 @@ def get(ctx: click.Context, key: Any) -> None:
with stream_file(file) as stream:
values = dotenv_values(stream=stream)

stored_value = values.get(key)
if stored_value:
click.echo(stored_value)
else:
# Empty strings are valid values; only missing keys / bare keys (None) fail.
if key not in values or values[key] is None:
sys.exit(1)
click.echo(values[key])


@cli.command()
Expand Down
9 changes: 9 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ def test_get_existing_value(cli, dotenv_path):
assert (result.exit_code, result.output) == (0, "b\n")


def test_get_empty_string_value(cli, dotenv_path):
"""Empty string values must not be treated as missing (truthiness trap)."""
dotenv_path.write_text("a=\n")

result = cli.invoke(dotenv_cli, ["--file", dotenv_path, "get", "a"])

assert (result.exit_code, result.output) == (0, "\n")


def test_get_non_existent_value(cli, dotenv_path):
result = cli.invoke(dotenv_cli, ["--file", dotenv_path, "get", "a"])

Expand Down