Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defend from AttributeErrors in CloudPath.__del__ (#418) #419

Merged
merged 1 commit into from Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion HISTORY.md
Expand Up @@ -2,7 +2,8 @@

## UNRELEASED

- Drop support for Python 3.7; pin minimal `boto3` version to Python 3.8+ versions. (PR [#407](https://github.com/drivendataorg/cloudpathlib/pull/407))
- Fix `CloudPath` cleanup via `CloudPath.__del__` when `Client` encounters an exception during initialization and does not create a `file_cache_mode` attribute. (Issue [#372](https://github.com/drivendataorg/cloudpathlib/issues/372), thanks to [@bryanwweber](https://github.com/bryanwweber))
- Drop support for Python 3.7; pin minimal `boto3` version to Python 3.8+ versions. (PR [#407](https://github.com/drivendataorg/cloudpathlib/pull/407))

## v0.18.1 (2024-02-26)

Expand Down
6 changes: 2 additions & 4 deletions cloudpathlib/cloudpath.py
Expand Up @@ -245,10 +245,8 @@ def __del__(self) -> None:
self._handle.close()

# ensure file removed from cache when cloudpath object deleted
if (
hasattr(self, "client")
and self.client.file_cache_mode == FileCacheMode.cloudpath_object
):
client = getattr(self, "client", None)
if getattr(client, "file_cache_mode", None) == FileCacheMode.cloudpath_object:
self.clear_cache()

def __getstate__(self) -> Dict[str, Any]:
Expand Down