File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -730,14 +730,26 @@ def _handle_401_token_refresh(
730
730
self ._request_params ["headers" ]["authorization" ] = f"Bearer { self .api_key } "
731
731
LOGGER .debug ("Successfully completed 401 automatic token refresh." )
732
732
733
- # Adding a short delay after token refresh
733
+ # Added a retry loop to ensure a token is active before retrying original request
734
734
# This helps ensure that when we fetch typedefs using the new token,
735
735
# the backend has fully recognized the token as valid.
736
736
# Without this delay, we occasionally get an empty response `[]` from the API,
737
737
# likely because the backend hasn’t fully propagated token validity yet.
738
738
import time
739
739
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
741
753
742
754
# Retry the API call with the new token
743
755
return self ._call_api_internal (
You can’t perform that action at this time.
0 commit comments