Skip to content

Commit 30132a2

Browse files
devin-ai-integration[bot]bot_apk
andcommitted
fix: address Copilot review — Response falsey check, sleep duration log, kwargs conflict
Co-Authored-By: bot_apk <apk@cognition.ai>
1 parent 789ce9d commit 30132a2

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

airbyte_cdk/sources/streams/http/rate_limiting.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,16 @@ def sleep_on_ratelimit(details: Mapping[str, Any]) -> None:
107107
_, exc, _ = sys.exc_info()
108108
if isinstance(exc, UserDefinedBackoffException):
109109
retry_after = exc.backoff
110-
if exc.response:
110+
sleep_time = retry_after + 1 # extra second to cover any fractions of second
111+
if exc.response is not None:
111112
logger.info(
112-
f"UserDefinedBackoffException: Rate limit exceeded (HTTP {exc.response.status_code}). Retrying in {retry_after} seconds."
113+
f"UserDefinedBackoffException: Rate limit exceeded (HTTP {exc.response.status_code}). Retrying in {sleep_time} seconds."
113114
)
114115
else:
115116
logger.info(
116-
f"UserDefinedBackoffException: Rate limit exceeded. Retrying in {retry_after} seconds."
117+
f"UserDefinedBackoffException: Rate limit exceeded. Retrying in {sleep_time} seconds."
117118
)
118-
time.sleep(retry_after + 1) # extra second to cover any fractions of second
119+
time.sleep(sleep_time)
119120

120121
def log_give_up(details: Mapping[str, Any]) -> None:
121122
_, exc, _ = sys.exc_info()
@@ -126,6 +127,9 @@ def log_give_up(details: Mapping[str, Any]) -> None:
126127
else:
127128
logger.error("Max retry limit reached for unknown request and response")
128129

130+
# Suppress the backoff library's default log that misleadingly reports interval (0s) instead of actual sleep time
131+
kwargs.pop("logger", None)
132+
129133
return backoff.on_exception( # type: ignore # Decorator function returns a function with a different signature than the input function, so mypy can't infer the type of the returned function
130134
backoff.constant,
131135
UserDefinedBackoffException,
@@ -135,7 +139,7 @@ def log_give_up(details: Mapping[str, Any]) -> None:
135139
jitter=None,
136140
max_tries=max_tries,
137141
max_time=max_time,
138-
logger=None, # suppress the backoff library's default log that misleadingly reports interval (0s) instead of actual sleep time
142+
logger=None,
139143
**kwargs,
140144
)
141145

0 commit comments

Comments
 (0)