From 4ae9505916cc875ad84737cd4fc05e28290d71cc Mon Sep 17 00:00:00 2001 From: Peter Foldes Date: Fri, 20 Feb 2026 20:50:09 -0800 Subject: [PATCH 1/2] fix: retry transient HTTP errors (502/503/504/429) during session polling The session status polling retry logic treated all requests.HTTPError as non-retryable, causing transient errors like 502 Bad Gateway to immediately fail the connection instead of retrying. This changes the retry strategy to use tenacity's composable retry_if_exception predicate to distinguish transient HTTP errors (429, 502, 503, 504) from permanent ones (401, 403, 404), matching the industry-standard status_forcelist from urllib3.util.Retry. --- wherobots/db/driver.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/wherobots/db/driver.py b/wherobots/db/driver.py index 4fb39cb..0da2eb6 100644 --- a/wherobots/db/driver.py +++ b/wherobots/db/driver.py @@ -46,6 +46,10 @@ threadsafety = 1 paramstyle: Final[str] = PARAM_STYLE +# HTTP status codes that indicate transient server-side issues and should be retried. +# This follows the industry-standard set used by urllib3.util.Retry's status_forcelist. +TRANSIENT_HTTP_STATUS_CODES = {429, 502, 503, 504} + def gen_user_agent_header(): try: @@ -135,9 +139,16 @@ def connect( @tenacity.retry( stop=tenacity.stop_after_delay(wait_timeout), wait=tenacity.wait_exponential(multiplier=1, min=1, max=5), - retry=tenacity.retry_if_not_exception_type( - (requests.HTTPError, OperationalError) + retry=( + tenacity.retry_if_exception( + lambda e: ( + isinstance(e, requests.HTTPError) + and e.response.status_code in TRANSIENT_HTTP_STATUS_CODES + ) + ) + | tenacity.retry_if_exception_type(tenacity.TryAgain) ), + reraise=True, ) def get_session_uri() -> str: r = requests.get(session_id_url, headers=headers) From 3044d56f136303a1f1e1e3a892914314cd371761 Mon Sep 17 00:00:00 2001 From: Peter Foldes Date: Fri, 20 Feb 2026 20:58:49 -0800 Subject: [PATCH 2/2] chore: bump version to 0.23.2 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d308171..db20516 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "wherobots-python-dbapi" -version = "0.23.1" +version = "0.23.2" description = "Python DB-API driver for Wherobots DB" authors = [{ name = "Maxime Petazzoni", email = "max@wherobots.com" }] requires-python = ">=3.10, <4"