Skip to content

fix: default TEMPDIR to system temp so S3 works with read-only CWD - #3372

Open
Shriprasad-P wants to merge 1 commit into
Netflix:masterfrom
Shriprasad-P:cursor/fix-s3-cwd-writeable-854-b94d
Open

fix: default TEMPDIR to system temp so S3 works with read-only CWD#3372
Shriprasad-P wants to merge 1 commit into
Netflix:masterfrom
Shriprasad-P:cursor/fix-s3-cwd-writeable-854-b94d

Conversation

@Shriprasad-P

Copy link
Copy Markdown

Fixes

Fixes #854

Summary

Default TEMPDIR to tempfile.gettempdir() instead of ., so the S3 client no longer requires the current working directory to be writable.

Test plan

  • Added unit test that instantiates S3 from a read-only CWD
  • Existing S3 unit tests still pass

The S3 client was using the current working directory (CWD) as the
default location for temporary files. This caused issues when the CWD
was read-only or not writable.

Changed TEMPDIR default from '.' to tempfile.gettempdir() which uses
the system's temporary directory (typically /tmp on Unix systems).

Added test to verify S3 client works correctly in read-only directories.

Fixes Netflix#854
@greptile-apps

greptile-apps Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR changes the default Metaflow temporary directory from the current working directory to Python’s system temporary directory.

  • Uses tempfile.gettempdir() as the default TEMPDIR.
  • Adds a unit test covering S3 initialization from a read-only working directory.

Confidence Score: 5/5

The PR appears safe to merge, with only previously reported non-blocking documentation and test-isolation concerns remaining.

No new issues were introduced since the previous review. The unresolved documentation thread remains outstanding because the public guidance was not updated, and the unresolved test thread remains outstanding because the assertion still depends on METAFLOW_TEMPDIR being unset; both are non-blocking.

Important Files Changed

Filename Overview
metaflow/metaflow_config.py Changes the default temporary-directory base to the system temporary directory.
test/unit/test_s3_readonly_cwd.py Adds coverage for constructing an S3 client while the current working directory is read-only.

Reviews (2): Last reviewed commit: "Fix S3 client to use system temp directo..." | Re-trigger Greptile

)

TEMPDIR = from_conf("TEMPDIR", ".")
TEMPDIR = from_conf("TEMPDIR", tempfile.gettempdir())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Documentation Has Stale Default

Changing TEMPDIR to use the system temporary directory leaves the public S3 documentation and remote-runtime comments saying that tmproot and current.tempdir default to the current working directory. This gives users incorrect guidance about where temporary files are created. Please update the affected documentation alongside the new default.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

assert not s3_client._tmpdir.startswith(readonly_dir)
# The temp dir should be in the system temp directory
system_temp = tempfile.gettempdir()
assert s3_client._tmpdir.startswith(system_temp)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Test Ignores Configured Tempdir

If METAFLOW_TEMPDIR is set, S3 uses that configured directory while this assertion still requires the path to start with tempfile.gettempdir(). The test then fails even though S3 behaves correctly. Please isolate this default-behavior test from the override or assert against the effective configured value.

@Shriprasad-P
Shriprasad-P force-pushed the cursor/fix-s3-cwd-writeable-854-b94d branch from 88d4d64 to 6c18caf Compare September 12, 2026 19:28
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.

S3 client should not expect current directory to be writeable

1 participant