fsspec / fsspec/filesystem_spec
`SimpleCacheFileSystem` ignores subfolder name if `same_names=True`, yielding invalid results
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.4k
- Forks
- 490
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 38
Description
This causes invalid reads from cached data if you have foo/file.txt and bar/file.txt as the cache seems to be completely flat. Possibly related to #633, in that the file cache keying could be enhanced to include additional data, like the full path and, for S3 the version ID.
WholeFileCacheFileSystem seems to work correctly in this case. is also bugged, but needs one more read call to expose the issue.
Here's a snippet that exemplifies the error:
import fsspec
from fsspec.implementations.cached import SimpleCacheFileSystem
def main():
base_fs = fsspec.filesystem("file")
filesystem = SimpleCacheFileSystem(
fs=base_fs, same_names=True, cache_storage="/tmp/fsspec-rfs-cache", cache_check=30
)
base_fs.mkdir("dog")
base_fs.mkdir("cat")
with filesystem.open("./dog/animal.txt", "w") as f:
f.write("woof")
with filesystem.open("./cat/animal.txt", "w") as f:
f.write("meow")
with filesystem.open("./dog/animal.txt", "r") as f:
assert f.read() == "woof"
with filesystem.open("./cat/animal.txt", "r") as f:
assert f.read() == "meow" # reads the wrong "animal.txt" in the cache - boom!
with filesystem.open("./dog/animal.txt", "r") as f:
assert f.read() == "woof" # WholeFileCacheFileSystem makes it until here, and then errors out
if __name__ == "__main__":
main()
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided reproduction with SimpleCacheFileSystem and WholeFileCacheFileSystem, then inspect the implementations of those classes and their cache-key handling. Confirm the behavior with two subfolders containing the same filename; done means reads return the content from the requested path consistently for both cache implementations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100