Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix read_env recursive bug #370

Merged
merged 6 commits into from
Nov 20, 2024
Merged

Conversation

senese
Copy link
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
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

@@ -463,6 +463,7 @@ def read_env(
False as a second positional argument.
"""

env_path = ""
Copy link
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
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.

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
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
8 checks passed
@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