From 7f09e56beedef6739cb0fc16b5866cea4bf614a5 Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Wed, 2 Dec 2026 21:55:55 -0800 Subject: [PATCH 1/2] Retry Drive's 409 Conflict in the tests' retry helper Drive sometimes answers 409 Conflict to a delete right after the file changed, which failed the cleanup of three live tests. Co-Authored-By: Claude Opus 5.5 --- pydrive2/test/test_util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pydrive2/test/test_util.py b/pydrive2/test/test_util.py index 8e324d15..18032493 100644 --- a/pydrive2/test/test_util.py +++ b/pydrive2/test/test_util.py @@ -48,7 +48,9 @@ def _call_once(call, *args, **kwargs): try: return call(*args, **kwargs) except ApiRequestError as exception: - if exception.error["code"] in [403, 500, 502, 503, 504]: + # Drive sometimes answers 409 Conflict to a delete right after the + # file changed. + if exception.error["code"] in [403, 409, 500, 502, 503, 504]: raise PyDriveRetriableError("Google API request failed") raise From 08e2d5342f996d260be7257f767658313d49c6eb Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Thu, 3 Dec 2026 11:01:39 -0800 Subject: [PATCH 2/2] Retry only Drive's conflict reason, and keep its error in the message Co-Authored-By: Claude Opus 5.5 --- pydrive2/test/test_util.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pydrive2/test/test_util.py b/pydrive2/test/test_util.py index 18032493..4c70988f 100644 --- a/pydrive2/test/test_util.py +++ b/pydrive2/test/test_util.py @@ -48,10 +48,14 @@ def _call_once(call, *args, **kwargs): try: return call(*args, **kwargs) except ApiRequestError as exception: + code = exception.error["code"] # Drive sometimes answers 409 Conflict to a delete right after the # file changed. - if exception.error["code"] in [403, 409, 500, 502, 503, 504]: - raise PyDriveRetriableError("Google API request failed") + conflict = code == 409 and exception.GetField("reason") == "conflict" + if conflict or code in [403, 500, 502, 503, 504]: + raise PyDriveRetriableError( + f"Google API request failed: {exception}" + ) from exception raise