-
Notifications
You must be signed in to change notification settings - Fork 64
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
Fix an error when incomplete S3Client is destroyed #373
Fix an error when incomplete S3Client is destroyed #373
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
|
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. |
@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() |
🎉 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.
@pjbull Change is made, sorry for the delay! |
@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. |
954a7bd
into
drivendataorg:373-client-del-exception
* 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 <[email protected]>
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.md
Closes #issue
appears in the PR summary (e.g.,Closes #123
).HISTORY.md
with 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.