Skip to content

Commit 17c66c4

Browse files
SG-38213 Prevent unexpected retries on error (#379)
* Prevent unexpected retries on error * Fix tests * Update shotgun_api3/shotgun.py Co-authored-by: Julien Langlois <[email protected]> * Packaging for v3.8.3-beta1 * Fix typo * Update HISTORY.rst Co-authored-by: Julien Langlois <[email protected]> --------- Co-authored-by: Julien Langlois <[email protected]>
1 parent bd4615c commit 17c66c4

File tree

4 files changed

+12
-48
lines changed

4 files changed

+12
-48
lines changed

HISTORY.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ Flow Production Tracking Python API Changelog
44

55
Here you can see the full list of changes between each Python API release.
66

7+
v3.8.5 (2025 Xxx X)
8+
===================
9+
10+
- We don't want to retry on general exceptions (e.g. timeout or remote disconnection)
11+
because we might send a resource modification request (create, batch create, etc) and
12+
we can end up duplicating things.
13+
714
v3.8.4 (2025 Jun 11)
815
====================
916

shotgun_api3/shotgun.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3938,11 +3938,10 @@ def _make_call(self, verb, path, body, headers):
39383938
if attempt == max_rpc_attempts:
39393939
LOG.debug("Request failed. Giving up after %d attempts." % attempt)
39403940
raise
3941-
except Exception:
3941+
except Exception as e:
39423942
self._close_connection()
3943-
if attempt == max_rpc_attempts:
3944-
LOG.debug("Request failed. Giving up after %d attempts." % attempt)
3945-
raise
3943+
LOG.debug(f"Request failed. Reason: {e}", exc_info=True)
3944+
raise
39463945

39473946
LOG.debug(
39483947
"Request failed, attempt %d of %d. Retrying in %.2f seconds..."

tests/test_api.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,42 +2223,8 @@ def test_make_call_retry(self, mock_request):
22232223

22242224
self.assertEqual(cm2.exception.args[0], "not working")
22252225
log_content = "\n".join(cm1.output)
2226-
for i in [1, 2]:
2227-
self.assertIn(
2228-
f"Request failed, attempt {i} of 3. Retrying",
2229-
log_content,
2230-
)
2231-
self.assertIn(
2232-
"Request failed. Giving up after 3 attempts.",
2233-
log_content,
2234-
)
2235-
2236-
# Then, make the exception happening only once and prove the
2237-
# retry works
2238-
def my_side_effect(*args, **kwargs):
2239-
try:
2240-
if my_side_effect.counter < 1:
2241-
raise Exception("not working")
2242-
2243-
return mock.DEFAULT
2244-
finally:
2245-
my_side_effect.counter += 1
2246-
2247-
my_side_effect.counter = 0
2248-
mock_request.side_effect = my_side_effect
2249-
with self.assertLogs("shotgun_api3", level="DEBUG") as cm:
2250-
self.assertIsInstance(
2251-
self.sg.info(),
2252-
dict,
2253-
)
2254-
2255-
log_content = "\n".join(cm.output)
22562226
self.assertIn(
2257-
"Request failed, attempt 1 of 3. Retrying",
2258-
log_content,
2259-
)
2260-
self.assertNotIn(
2261-
"Request failed, attempt 2 of 3. Retrying",
2227+
"Request failed. Reason: not working",
22622228
log_content,
22632229
)
22642230

tests/test_client.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,17 +330,9 @@ def test_network_retry(self):
330330
with mock.patch("time.sleep") as mock_sleep:
331331
self.assertRaises(httplib2.HttpLib2Error, self.sg.info)
332332
self.assertTrue(
333-
self.sg.config.max_rpc_attempts == self.sg._http_request.call_count,
333+
self.sg._http_request.call_count == 1,
334334
"Call is repeated",
335335
)
336-
# Ensure that sleep was called with the retry interval between each attempt
337-
attempt_interval = self.sg.config.rpc_attempt_interval / 1000.0
338-
calls = [mock.callargs(((attempt_interval,), {}))]
339-
calls *= self.sg.config.max_rpc_attempts - 1
340-
self.assertTrue(
341-
mock_sleep.call_args_list == calls,
342-
"Call is repeated at correct interval.",
343-
)
344336

345337
def test_set_retry_interval(self):
346338
"""Setting the retry interval through parameter and environment variable works."""

0 commit comments

Comments
 (0)