Skip to content

OverwriteNewerFile error on low-latency cloud calls #49

Open
@pjbull

Description

@pjbull

Code like this will fail intermittently, likely because a transaction hasn't finished or a place where the cloud is updated before the local file edit time is updated.

s3p = S3Path("s3://pjb-testing-bucket-for-platform/file.txt")

s3p.touch()
s3p.exists()
s3p.write_text("a")
s3p.unlink()

With a traceback that looks like:

---------------------------------------------------------------------------
OverwriteNewerCloud                       Traceback (most recent call last)
 in 
      3 s3p.touch()
      4 s3p.exists()
----> 5 s3p.write_text("a")
      6 s3p.unlink()

~/code/cloudpathlib/cloudpathlib/cloudpath.py in write_text(self, data, encoding, errors)
    376             raise TypeError("data must be str, not %s" % data.__class__.__name__)
    377         with self.open(mode="w", encoding=encoding, errors=errors) as f:
--> 378             return f.write(data)
    379 
    380     # ====================== DISPATCHED TO POSIXPATH FOR PURE PATHS ======================

~/code/cloudpathlib/cloudpathlib/cloudpath.py in _patched_close(*args, **kwargs)
    310             def _patched_close(*args, **kwargs):
    311                 original_close(*args, **kwargs)
--> 312                 self._upload_local_to_cloud(force_overwrite_to_cloud=force_overwrite_to_cloud)
    313 
    314             buffer.close = _patched_close

~/code/cloudpathlib/cloudpathlib/cloudpath.py in _upload_local_to_cloud(self, force_overwrite_to_cloud)
    605 
    606         # cloud is newer and we are not overwriting
--> 607         raise OverwriteNewerCloud(
    608             f"Local file ({self._local}) for cloud path ({self}) is newer in the cloud disk, but "
    609             f"is being requested to be uploaded to the cloud. Either (1) redownload changes from the cloud or "

OverwriteNewerCloud: Local file (/var/folders/8g/v8lwvfhj6_l6ct_zd_rs84mw0000gn/T/tmp5jl8mhwn/pjb-testing-bucket-for-platform/file.txt) for cloud path (s3://pjb-testing-bucket-for-platform/file.txt) is newer in the cloud disk, but is being requested to be uploaded to the cloud. Either (1) redownload changes from the cloud or (2) pass `force_overwrite_to_cloud=True` to overwrite.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions