drivendataorg / drivendataorg/cloudpathlib
open(cloud_path) acts on cached local file instead of cloud file
- Dominant language
- Python
- Stars
- 628
- Forks
- 88
- Avg merge
- 17h 28m
- Merged PRs (30d)
- 2
Description
Unfortunately the following code does not behave as expected:
```python
with open(cloud_path, "w") as fp:
fp.write("foo")
```
(as opposed to using `cloud_path.open("w")` which does work as expected).
What will happen is that this will only modify the local cached copy of the file without uploading it to the cloud. Then further attempts to interact with the cloud path will correctly raise `OverwriteNewerLocal` exceptions. Because cloud paths have an `__fspath__` method (#72) that returns the local file path, the `open` function will only interact with that local file path.
Users can still get the correct behavior by using the `open` method. However, I've seen a lot of people using regular pathlib, especially those who are still new to it, with `open(path, "w")` on their `Path` objects, so I expect this may be a common pattern for users of cloudpathlib as well.
Contributor guide
Assessment
This issue has not been assessed yet.