Skip to content

fix: warn when the given .env path is a directory - #748

Open
boriskozak wants to merge 2 commits into
theskumar:mainfrom
boriskozak:python-dotenv-427-fix
Open

boriskozak wants to merge 2 commits into
theskumar:mainfrom
boriskozak:python-dotenv-427-fix

Conversation

@boriskozak

Copy link
Copy Markdown

Fixes #427

Passing a directory as dotenv_path to load_dotenv (or dotenv_values / get_key) silently loaded nothing, even with verbose=True. The CLI half of this was fixed in #441, but the library half stayed silent.

Now DotEnv._get_stream logs a warning when the given path exists but is not a regular file or FIFO:

python-dotenv could not load configuration file /path/to/dir: it is not a file.

Return values are unchanged (False / {}), so the lenient missing-file contract is preserved, and an explicitly passed stream still takes precedence over the path. The old misleading "could not find configuration file" info message no longer fires for this case under verbose=True.

Testing: 3 new tests in tests/test_main.py (directory warns for load_dotenv with verbose on/off, dotenv_values, and stream-takes-precedence). Full suite: 156 passed, 3 skipped, 1 failed (test_load_dotenv_in_current_dir, fails identically on clean main in this environment). ruff check and ruff format --check pass.

This branch has not been deployed

No deployments
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.

Doesn't accept any pathnames nor show errors on python 3.9.2 / raspberry pi

1 participant