Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Atomic append fails to create a missing file

Open Beginner friendly
#201 0 comments 0 reactions 0 assignees View on GitHub

@harbinresearcher is already working on this.

Since Oct 14, 2026.

  • #202 by @harbinresearcher — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start in _write_file_atomic, where the destination is read unconditionally when append=True before the temporary file is created. Run the reproduction in the issue with atomic=True and a missing parent directory and file, then compare with the atomic=False path. Done means the atomic append creates the missing file, a second append keeps earlier content, and the existing tests still pass.

Written by the indexing model from the issue text.

Description

Describe the bug

write_file(path, content, append=True, atomic=True) raises OSError: Invalid file path when the destination does not exist. The same call with atomic=False creates the file, consistent with append mode.

Reproduce
from pathlib import Path
from tempfile import TemporaryDirectory

import fsutil

with TemporaryDirectory() as directory:
    path = str(Path(directory) / "new" / "file.txt")
    fsutil.write_file(path, content="first", append=True, atomic=True)

Reproduced with Python 3.12.14 on Windows and python-fsutil 0.18.0 source at d3a77c552346dc72a081284a6fd017ecc1ba234f. No mocked filesystem or injected failure is required. This was found during a code review, rather than reported from a production application.

Expected behavior

Create the missing file, as non-atomic append does. A subsequent append should preserve its previous content.

Cause and scope

_write_file_atomic reads the destination unconditionally when append=True, before creating a temporary file. Reading a missing destination raises immediately.

This differs from #194: it does not concern errors after replacement or the Windows-specific FileNotFoundError cleanup handler. Those paths can remain unchanged.

AI assistance was used to investigate the source and prepare reproduction and tests. A focused fix is ready.

Dominant language
Python
Stars
268
Forks
19
Avg merge
8d 13h
Merged PRs (30d)
4

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fabiocaccamo/python-fsutil

All issues in fabiocaccamo/python-fsutil

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.