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

Fix an error when incomplete S3Client is destroyed (#373) #375

Merged
merged 1 commit into from
Nov 1, 2023

Conversation

pjbull
Copy link
Member

@pjbull pjbull commented Nov 1, 2023

Repo-local PR for live tests of #373


  • 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.

Closes #372

* 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
Copy link
Contributor

github-actions bot commented Nov 1, 2023

@github-actions github-actions bot temporarily deployed to pull request November 1, 2023 20:24 Inactive
Copy link

codecov bot commented Nov 1, 2023

Codecov Report

Merging #375 (954a7bd) into master (ffbdd1c) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Additional details and impacted files
@@          Coverage Diff           @@
##           master    #375   +/-   ##
======================================
  Coverage    93.7%   93.7%           
======================================
  Files          22      22           
  Lines        1563    1563           
======================================
+ Hits         1465    1466    +1     
+ Misses         98      97    -1     
Files Coverage Δ
cloudpathlib/client.py 89.6% <100.0%> (ø)

... and 2 files with indirect coverage changes

@pjbull
Copy link
Member Author

pjbull commented Nov 1, 2023

Everything passes here, so I will merge. I think the windows test on #373 may just have been flaky. Thanks @bryanwweber!

@pjbull pjbull merged commit b508f7d into master Nov 1, 2023
28 checks passed
@pjbull pjbull deleted the 373-client-del-exception branch November 1, 2023 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AttributeError when __del__ is called on S3Client that errors during __init__
2 participants