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

Infinte recursion on Windows+IPython if caller path on drive different than working path #172

Open
jdranczewski opened this issue Aug 22, 2024 · 1 comment · May be fixed by #174
Open

Comments

@jdranczewski
Copy link

When the imported file calling config is for example on the D: drive, the recurrent function that searches its parent folders will eventually reach D:/. Unfortunately, the check that's meant to stop the recursion considers the drive of the working directory (say, C:/) to be the top folder in some circumstances. The offending lines are these:

python-decouple/decouple.py

Lines 220 to 223 in 0573e6f

# search the parent
parent = os.path.dirname(path)
if parent and os.path.normcase(parent) != os.path.normcase(os.path.abspath(os.sep)):
return self._find_file(parent)

This results in a silent crash of whatever code is running, but only when the working directory is on a drive different than the drive where the file using config is, I think? It also only happens in IPython, which may be handling working directories differently. This made it quite amusing to diagnose (I was using a different library that imports decouple), and I presume it may make it difficult to reproduce easily.

I suggest replacing the check with:

os.path.normcase(parent) != os.path.normcase(path)

which will catch if the parent is the same as the current path more explicitly.

@jdranczewski
Copy link
Author

Ah, the different behaviour under Python and IPython is because on my machine Python correctly raises the RecursionError, which gets caught by the try ... except block in _load, but in IPython the recursion Exception is not raised correctly and the process crashes. This seems to be an issue in IPython: ipython/ipython#12197

So it's both a problem of the recursion happening and IPython handling it badly.

jdranczewski added a commit to jdranczewski/python-decouple that referenced this issue Nov 25, 2024
@jdranczewski jdranczewski linked a pull request Nov 25, 2024 that will close this issue
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 a pull request may close this issue.

1 participant