Skip to content

fix: find_dotenv fall back to cwd when stack exhausted (#499) - #707

Open
Pitchfork-and-Torch wants to merge 1 commit into
theskumar:mainfrom
Pitchfork-and-Torch:cook/find-dotenv-no-assert-fallback
Open

Pitchfork-and-Torch wants to merge 1 commit into
theskumar:mainfrom
Pitchfork-and-Torch:cook/find-dotenv-no-assert-fallback

Conversation

@Pitchfork-and-Torch

Copy link
Copy Markdown

Summary

Fixes #499. When every caller frame is the dotenv module or a non-existent filename (python -c, runpy, stdin), find_dotenv asserted frame.f_back is not None and raised AssertionError. Fall back to getcwd() instead (same as the interactive path).

Test plan

  • pytest tests/test_main.py::test_find_dotenv_no_assert_when_stack_exhausted
  • python -c "from dotenv import find_dotenv; print(find_dotenv())" from a directory containing .env no longer AssertionErrors

Walking caller frames for a real filename asserted f_back is not None,
which raised AssertionError under python -c / runpy / stdin. Fall back to
getcwd() instead, matching the interactive path.
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.

AssertionError when attempting to locate dotenv file

1 participant