Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: silence TypeError during tear down stage #1027

Merged
merged 2 commits into from
Apr 21, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions google/auth/transport/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,14 @@ def __init__(self, session=None):
self.session = session

def __del__(self):
if hasattr(self, "session") and self.session is not None:
self.session.close()
try:
if hasattr(self, "session") and self.session is not None:
self.session.close()
except TypeError:
# NOTE: For certain Python binary built, the queue.Empty exception
# might not be considered a normal Python exception causing
# TypeError.
pass

def __call__(
self,
Expand Down
6 changes: 6 additions & 0 deletions tests/transport/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def test_session_closed_on_del(self):
request.__del__()
http.close.assert_called_with()

http = mock.create_autospec(requests.Session, instance=True)
http.close.side_effect = TypeError("test injected TypeError")
request = google.auth.transport.requests.Request(http)
request.__del__()
http.close.assert_called_with()


class TestTimeoutGuard(object):
def make_guard(self, *args, **kwargs):
Expand Down