Fix an error when incomplete S3Client is destroyed#373
Merged
pjbull merged 2 commits intodrivendataorg:373-client-del-exceptionfrom Nov 1, 2023
bryanwweber:fix-del-bug-in-client
Merged
Fix an error when incomplete S3Client is destroyed#373pjbull merged 2 commits intodrivendataorg:373-client-del-exceptionfrom bryanwweber:fix-del-bug-in-client
pjbull merged 2 commits intodrivendataorg:373-client-del-exceptionfrom
bryanwweber:fix-del-bug-in-client
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #373 +/- ##
========================================
- Coverage 93.7% 93.2% -0.5%
========================================
Files 22 22
Lines 1563 1563
========================================
- Hits 1465 1458 -7
- Misses 98 105 +7
|
Contributor
Author
|
I don't have a Windows machine available and all the tests pass locally for me on my Mac. I think I'll need some help to debug and fix that. |
Member
|
@bryanwweber I have a preference to do this with E.g., def __del__(self) -> None:
# remove containing dir, even if a more aggressive strategy
# removed the actual files
if getattr(self, "file_cache_mode", None) in [
FileCacheMode.tmp_dir,
FileCacheMode.close_file,
FileCacheMode.cloudpath_object,
]:
self.clear_cache()
if self._local_cache_dir.exists():
self._local_cache_dir.rmdir() |
Contributor
Author
|
🎉 great idea @pjbull! I'll make that change |
If an error occurs during initialization of the S3Client instance, the initializer for the Client superclass is never called. This could happen, for example, when the S3Client has a bad profile name passed which botocore doesn't understand. When the remainder of the class is garbage collected (for example, at interpreter shutdown), Python calls the __del__ method of the Client superclass. The specific error is that the file_cache_mode attribute is not set because the superclass initializer is not called in the S3Client initializer if an error occurs during S3 session setup. This change uses getattr with a default value to avoid the AttributeError in the __del__ method.
Contributor
Author
|
@pjbull Change is made, sorry for the delay! |
Member
|
@bryanwweber I don't think the Windows failure is due to your change. Going to merge into a repo-local branch to see if that passes, and if not tweak the test on that branch. |
pjbull
added a commit
that referenced
this pull request
Nov 1, 2023
* Fix an error when incomplete S3Client is destroyed If an error occurs during initialization of the S3Client instance, the initializer for the Client superclass is never called. This could happen, for example, when the S3Client has a bad profile name passed which botocore doesn't understand. When the remainder of the class is garbage collected (for example, at interpreter shutdown), Python calls the __del__ method of the Client superclass. The specific error is that the file_cache_mode attribute is not set because the superclass initializer is not called in the S3Client initializer if an error occurs during S3 session setup. This change uses getattr with a default value to avoid the AttributeError in the __del__ method. * Update history file Co-authored-by: Bryan Weber <bryan.w.weber@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If an error occurs during initialization of the S3Client instance, the initializer for the Client superclass is never called. This could happen, for example, when the S3Client has a bad profile name passed which botocore doesn't understand. The specific error is that the file_cache_mode attribute is not set because the superclass initializer is not called in the S3Client initializer if an error occurs during S3 session setup. This commit moves the superclass initializer to the top of the S3Client initializer to ensure that all superclass attributes are defined if/when any errors occur.
The same fix is applied for the Google client and the local client.
Closes #372
Contributor checklist:
CONTRIBUTING.mdCloses #issueappears in the PR summary (e.g.,Closes #123).HISTORY.mdwith the issue that is addressed and the PR you are submitting. If the top section is not `## UNRELEASED``, then you need to add a new section to the top of the document for your change.