Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 84ccb95

Browse files
authored
Fix a bug where an unbounded number of credentials wrappers got added. (#296)
* Fix a bug where an unbounded number of credentials wrappers got added. This fixes #1251, where the fact that we were sharing a single `httplib2.Http` instance caused each request to add an additional credentials wrapper around that single instance. That, in turn, caused a `RuntimeError: maximum recursion depth ...` error message once too many API calls had been made. * Only copy the http instance when we need to * Include the fix for authorizing HTTP requests in the older `datalab` module
1 parent 469da4b commit 84ccb95

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

datalab/utils/_http.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from past.builtins import basestring
2020
from builtins import object
2121

22+
import copy
2223
import datetime
2324
import json
2425
import urllib.request, urllib.parse, urllib.error
@@ -119,9 +120,12 @@ def request(url, args=None, data=None, headers=None, method=None,
119120
if method is None:
120121
method = 'GET'
121122

122-
# Authorize with credentials if given.
123123
http = Http.http
124+
125+
# Authorize with credentials if given.
124126
if credentials is not None:
127+
# Make a copy of the shared http instance before we modify it.
128+
http = copy.copy(http)
125129
http = credentials.authorize(http)
126130
if stats is not None:
127131
stats['duration'] = datetime.datetime.utcnow()

google/datalab/utils/_http.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from past.builtins import basestring
2020
from builtins import object
2121

22+
import copy
2223
import datetime
2324
import json
2425
import urllib.request, urllib.parse, urllib.error
@@ -119,9 +120,12 @@ def request(url, args=None, data=None, headers=None, method=None,
119120
if method is None:
120121
method = 'GET'
121122

122-
# Authorize with credentials if given
123123
http = Http.http
124+
125+
# Authorize with credentials if given
124126
if credentials is not None:
127+
# Make a copy of the shared http instance before we modify it.
128+
http = copy.copy(http)
125129
http = credentials.authorize(http)
126130
if stats is not None:
127131
stats['duration'] = datetime.datetime.utcnow()

0 commit comments

Comments
 (0)