python-dotenv-vault icon indicating copy to clipboard operation
python-dotenv-vault copied to clipboard

Incorrect fallback behavior when `DOTENV_KEY` is not set

Open tunakasif opened this issue 8 months ago • 0 comments
trafficstars

The expected behavior of the load_dotenv() is to fall back to the behavior of the python-dotenv library, if the DOTENV_KEY environment variable is not set, as suggested in the function comments.

The python-dotenv library allows a non-existing .env file, and load_dotenv() returns False without raising an error in such a case. However, due to src/dotenv_vault/main.py#L67-L68, the behavior differs:

dotenv_path = dotenv.find_dotenv(usecwd=True)
stream = open(dotenv_path) if not stream else stream

Since dotenv.find_dotenv(usecwd=True) returns '' in the non-existing .env file case, the following open(dotenv_path) raises FileNotFoundError. Hence, this differs from the python-dotenv's behavior, contradicting the statement "falls back to the behavior of the python-dotenv library."

tunakasif avatar Mar 17 '25 16:03 tunakasif