Skip to content

Incorrect fallback behavior when DOTENV_KEY is not set #27

@tunakasif

Description

@tunakasif

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."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions