Skip to content

Commit 8a9c6a7

Browse files
fix: silence TypeError during tear down stage (#1027)
Co-authored-by: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com>
1 parent d815dcd commit 8a9c6a7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/google-auth/google/auth/transport/requests.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,14 @@ def __init__(self, session=None):
150150
self.session = session
151151

152152
def __del__(self):
153-
if hasattr(self, "session") and self.session is not None:
154-
self.session.close()
153+
try:
154+
if hasattr(self, "session") and self.session is not None:
155+
self.session.close()
156+
except TypeError:
157+
# NOTE: For certain Python binary built, the queue.Empty exception
158+
# might not be considered a normal Python exception causing
159+
# TypeError.
160+
pass
155161

156162
def __call__(
157163
self,

packages/google-auth/tests/transport/test_requests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ def test_session_closed_on_del(self):
5757
request.__del__()
5858
http.close.assert_called_with()
5959

60+
http = mock.create_autospec(requests.Session, instance=True)
61+
http.close.side_effect = TypeError("test injected TypeError")
62+
request = google.auth.transport.requests.Request(http)
63+
request.__del__()
64+
http.close.assert_called_with()
65+
6066

6167
class TestTimeoutGuard(object):
6268
def make_guard(self, *args, **kwargs):

0 commit comments

Comments
 (0)