Skip to content

Fix read_env recursive bug#370

Merged
sloria merged 6 commits intosloria:mainfrom
senese:bugfix/always_recursive
Nov 20, 2024
Merged

Fix read_env recursive bug#370
sloria merged 6 commits intosloria:mainfrom
senese:bugfix/always_recursive

Conversation

@senese
Copy link
Copy Markdown
Contributor

@senese senese commented Nov 15, 2024

The feature added by #364 introduced a behavior that read_env() would always recurse the tree directory even when it has already found a .env file. Sorry about that.

If you would have a .env file on your current working directory this file would be chosen instead another .env more deep on the tree where read_env() was called.

Bug fixed and I added tests to caught this behavior on future releases.

Copy link
Copy Markdown
Owner

@sloria sloria left a comment

Choose a reason for hiding this comment

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

Good catch! Just a few nits. I'll push up some test improvements shortly

Comment thread src/environs/__init__.py Outdated
False as a second positional argument.
"""

env_path = ""
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This results in an empty string being returned if a .env file isn't found. Not sure if this is the most intuitive; perhaps None should be returned?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

None works as well but my thought was to mimic the same behavior as find_dotenv(). None and an empty string works the same way for conditional checks, but I think None is more representative indeed.

Comment thread tests/test_environs.py Outdated
def test_read_env_return_path_with_dotenv_on_working_dir(self, env):
working_dir = pathlib.Path(os.getcwd())
dotenv_path = working_dir / ".env"
open(dotenv_path, "x") # create .env on working dir
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This will result in a failure if the assertion fails and the test is re-run. I'll push up a fix for this shortly

@sloria sloria merged commit 9d1ff82 into sloria:main Nov 20, 2024
@senese senese deleted the bugfix/always_recursive branch November 22, 2024 02:09
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.

2 participants