drivendataorg / drivendataorg/cloudpathlib

Opening file for writing in append mode on inexistant file fails

Open
#585 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
628
Forks
88
Avg merge
17h 28m
Merged PRs (30d)
2

Description

I normally write in append mode when I want to append my error traces as to not erase every different threads messages into a file. Calling open in append on an inexistant file works in python and doesn't trigger an error. I can't see why this isn't supported and would need help understanding.

The code that seems to cause the issus is the following ;
``` python
if not exists_on_cloud and any(m in mode for m in ("r", "a")):
raise CloudPathFileNotFoundError(
f"File opened for read or append, but it does not exist on cloud: {self}"
)
```

Opening a file for writing in general seems supported.

My suggestion is to support "append" mode so as to give a nice feature for everybody, but I understand I may be missing something here. If I'm missing something indeed, then I would instead align the behaviour to block local append mode through the library as to avoid surprise in production environment where append mode might be blocked.

Contributor guide

Open the contributing guide

Research direction

Start at the cloud-path open logic containing the shown exists_on_cloud and mode check, then compare its append handling with the existing write behavior and open-mode tests. Resolve whether append should create a missing cloud file or remain blocked, and cover the chosen behavior with a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cloud
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.