File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 (
You can’t perform that action at this time.
0 commit comments