-
Notifications
You must be signed in to change notification settings - Fork 88
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
Conversation
There was a problem hiding this 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
src/environs/__init__.py
Outdated
@@ -463,6 +463,7 @@ def read_env( | |||
False as a second positional argument. | |||
""" | |||
|
|||
env_path = "" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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
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.