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

session.create_tmp has slightly surprising behavior #713

Closed
Julian opened this issue May 31, 2023 · 2 comments
Closed

session.create_tmp has slightly surprising behavior #713

Julian opened this issue May 31, 2023 · 2 comments

Comments

@Julian
Copy link
Contributor

Julian commented May 31, 2023

How would this feature be useful?

I'm in the middle of diagnosing some build instability (files appearing in a directory which I don't expect to be there) and in the process noticed something about .create_tmp -- I'm not sure it's related to my specific issue yet, but to me it seems worth addressing independently. Filing to see what others think.

Specifically... session.create_tmp is documented as "create and return a temporary directory" -- but it actually seems to always use a fixed directory path, tmp, and one that may exist "accidentally" if some other thing happened to create a directory named that, or get polluted accidentally if some other process starts writing to that path.

More surprisingly I think is if someone does this:

@session()
def foo(session):
    one = session.create_tmp()
    two = session.create_tmp()

they actually are unlikely to realize that they've gotten the same exact path twice there, one and two are going to be the same tmp/ directory.

Describe the solution you'd like

I'd personally definitely expect behavior more like tempfile.TemporaryDirectory and os.mkdtemp, namely that creating temporary directories gives me a path to a directory I can be sure:

  • didn't exist beforehand
  • isn't going to be being used by some other process
  • is going to differ if I call it twice

Describe alternatives you've considered

Certainly just ignoring session.create_tmp is an option, but filing this as it seems a bit like a small footgun as-is.

Anything else?

No response

@Julian
Copy link
Contributor Author

Julian commented Jun 1, 2023

It was pointed out to me that create_tmp also sets TMPDIR (which indeed explains my original issue) -- that seems like even more surprising behavior than the first part to me. It now seems worth avoiding this function entirely to me, so going to close this, but obviously if someone agrees with my assessment (on both being quite surprising behavior) and thinks there's some way to nudge it to have less surprising behavior, let me know.

@Julian Julian closed this as not planned Won't fix, can't repro, duplicate, stale Jun 1, 2023
@pquentin
Copy link

if someone agrees with my assessment (on both being quite surprising behavior) and thinks there's some way to nudge it to have less surprising behavior, let me know.

Since you asked :) I was expecting create_tmp to be a simple wrapper around https://docs.python.org/3/library/tempfile.html#tempfile.TemporaryDirectory that does not do anything fancy like setting TMPDIR. As it stands, create_tmp is an attractive nuisance. It appears useful, but has multiple important caveats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants