Skip to content

fix: find dotenv from direct thread targets - #705

Open
ryanchou1994 wants to merge 2 commits into
theskumar:mainfrom
ryanchou1994:fix/thread-find-dotenv
Open

ryanchou1994 wants to merge 2 commits into
theskumar:mainfrom
ryanchou1994:fix/thread-find-dotenv

Conversation

@ryanchou1994

Copy link
Copy Markdown

Fixes #531.

When load_dotenv is used directly as a threading.Thread target, the first caller frame belongs to the standard library's threading module. find_dotenv() therefore starts its search next to threading.py and misses the application's current-directory .env.

This change recognizes the actual standard-library module globals by identity and uses the current directory for that direct-target case. Calls through a user wrapper still search relative to the wrapper file, and a user module merely named threading is not mistaken for the standard library.

Tests cover the direct thread target, wrapper behavior, and the same-name module regression.

Validation:

  • Linux Python 3.13: 257 passed, 1 skipped
  • Ruff check and format check
  • mypy for Python 3.10 through 3.14

Copilot AI lite review requested due to automatic review settings September 15, 2026 11:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

find_dotenv() fails when it is the target of a thread

2 participants