Skip to content

Commit 22b4d11

Browse files
authored
Merge pull request #638 from atlanhq/APP-6710
APP-6710: Added a retry loop to ensure a token is active before retrying original request
2 parents 5aaa2db + 4f1c498 commit 22b4d11

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pyatlan/client/atlan.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,14 +730,26 @@ def _handle_401_token_refresh(
730730
self._request_params["headers"]["authorization"] = f"Bearer {self.api_key}"
731731
LOGGER.debug("Successfully completed 401 automatic token refresh.")
732732

733-
# Adding a short delay after token refresh
733+
# Added a retry loop to ensure a token is active before retrying original request
734734
# This helps ensure that when we fetch typedefs using the new token,
735735
# the backend has fully recognized the token as valid.
736736
# Without this delay, we occasionally get an empty response `[]` from the API,
737737
# likely because the backend hasn’t fully propagated token validity yet.
738738
import time
739739

740-
time.sleep(5)
740+
retry_count = 1
741+
while retry_count <= self.retry.total:
742+
try:
743+
response = self.typedef.get(type_category=[AtlanTypeCategory.STRUCT])
744+
if response and response.struct_defs:
745+
break
746+
except Exception as e:
747+
LOGGER.debug(
748+
"Retrying to get typedefs (to ensure token is active) after token refresh failed: %s",
749+
e,
750+
)
751+
time.sleep(retry_count) # Linear backoff
752+
retry_count += 1
741753

742754
# Retry the API call with the new token
743755
return self._call_api_internal(

0 commit comments

Comments
 (0)