MemoryFileSystem: create the file when appending to a missing path - #2062
Merged
martindurant merged 2 commits intoJul 6, 2026
Merged
Conversation
Opening a non-existent path in append mode ("a"/"ab"/"a+b") on
MemoryFileSystem raised FileNotFoundError, unlike builtin open() and
LocalFileSystem, which create the file. Create it in that case, and add
a regression test.
martindurant
reviewed
Jul 3, 2026
Comment on lines
+203
to
+205
| m = MemoryFile(self, path, kwargs.get("data")) | ||
| if not self._intrans: | ||
| m.commit() |
Member
There was a problem hiding this comment.
Should make sure to seek to the end of the file. In the test, it is already at the end, but this is not guaranteed.
Per review: explicitly position the append-created file at the end, matching the existing-file append path, instead of relying on the new file being empty. Assert the position in the regression test.
Contributor
Author
|
Good point @martindurant, thanks! Pushed a commit that seeks to the end explicitly after creating the file, so it matches the existing-file append path and no longer relies on the new file being empty. Also updated the regression test to assert the position is at the end. |
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.
Opening a path that doesn't exist yet in append mode behaves differently on MemoryFileSystem than on LocalFileSystem and the builtin
open:open(path, "ab") creates the file if it's missing, and LocalFileSystem inherits that, so having the memory backend raise FileNotFoundError here is surprising. This makes _open create an empty file when the path isn't in the store yet for append modes (a/ab/a+b), then position at the end as before. Read modes (rb/r+b) are unchanged and still raise.
Added a regression test covering the three append modes.