fix: tolerate chmod PermissionError on flat-permission filesystems#8146
Open
dschulmeist wants to merge 1 commit intohuggingface:mainfrom
Open
fix: tolerate chmod PermissionError on flat-permission filesystems#8146dschulmeist wants to merge 1 commit intohuggingface:mainfrom
dschulmeist wants to merge 1 commit intohuggingface:mainfrom
Conversation
…uggingface#8125) map() and the indices cache writer both call os.chmod on the freshly moved cache file. On flat-permission filesystems (GCS FUSE, S3 FUSE mounts) chmod raises PermissionError / OSError, aborting the whole map() call even though the cache file itself was written successfully. Wrap each chmod in try/except OSError with a debug log. The chmod remains best-effort: it still sets sane 0o666-masked permissions on filesystems that support it, and silently degrades on ones that don't. Adds a regression test that patches os.chmod to raise PermissionError only for paths inside the pytest tmp-path and asserts that Dataset.map still returns the correct mapped values and the cache file ends up on disk. Fixes huggingface#8125
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #8125.
Dataset.map()(and the indices writer inDataset.flatten_indices/Dataset.selectpath) callsos.chmod(cache_file, 0o666 & ~umask)on the freshly moved cache file. On flat-permission filesystems — GCS FUSE, S3 FUSE mounts, and similar object-storage-backed mounts —chmodraisesPermissionError(a subclass ofOSError). The cache file itself is already written successfully at that point, but the unguarded chmod takes down the whole.map()call with a traceback like:Fix
Wrap each of the two
os.chmodcall sites insrc/datasets/arrow_dataset.pywithtry/except OSError, logging the failure at debug level. The permission update stays best-effort: sane0o666 & ~umaskpermissions on POSIX filesystems that support it, silent graceful degradation on flat-permission mounts where there's nothing to set.No new API surface, no env-var toggle — the issue body suggested an opt-out env var, but catching
OSErroris narrower and doesn't require users to know about a new knob. If a future caller actually needs to detect the degraded mode, they can observe the debug log.Tests
New regression test
test_map_survives_chmod_permission_errorintests/test_arrow_dataset.py:datasets.arrow_dataset.os.chmodto raisePermissionErrorfor paths inside the pytesttmp_path(so pytest's own housekeeping is unaffected)Dataset.from_dict({\"a\": [1, 2, 3]}).map(lambda x: {\"b\": x[\"a\"] * 2}, cache_file_name=...)[2, 4, 6]), the cache file exists on disk, and the chmod guard was actually exercisedVerified the test fails on
mainwithout the fix (propagatesPermissionError) and passes with it.Scope notes
arrow_dataset.py— both follow the identicalshutil.move → umask → chmodpatternChecklist
tests/ruff checkandruff format --checkclean on touched filestest_map_caching*tests still pass