Skip to content

Commit 04c509d

Browse files
committed
Adding explicit timeout to whoami()
1 parent 735f9f6 commit 04c509d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/groundlight/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,12 @@ def __init__(
154154
self.image_queries_api = ImageQueriesApi(self.api_client)
155155
self.user_api = UserApi(self.api_client)
156156
self.labels_api = LabelsApi(self.api_client)
157+
self.logged_in_user = "(not-logged-in)"
157158
self._verify_connectivity()
158159

159160
def __repr__(self) -> str:
160-
return f"Logged in as {self.whoami()} to Groundlight at {self.endpoint}"
161+
# Don't call the API here because it that can get us stuck in a loop rendering exception strings
162+
return f"Logged in as {self.logged_in_user} to Groundlight at {self.endpoint}"
161163

162164
def _verify_connectivity(self) -> None:
163165
"""
@@ -166,7 +168,7 @@ def _verify_connectivity(self) -> None:
166168
"""
167169
try:
168170
# a simple query to confirm that the endpoint & API token are working
169-
self.whoami()
171+
self.logged_in_user = self.whoami()
170172
if self._user_is_privileged():
171173
logger.warning(
172174
"WARNING: The current user has elevated permissions. Please verify such permissions are necessary"
@@ -204,7 +206,7 @@ def whoami(self) -> str:
204206
205207
:return: str
206208
"""
207-
obj = self.user_api.who_am_i()
209+
obj = self.user_api.who_am_i(_request_timeout=DEFAULT_REQUEST_TIMEOUT)
208210
return obj["email"]
209211

210212
def _user_is_privileged(self) -> bool:

0 commit comments

Comments
 (0)