altcodepro-polydb-python 2.3.17__py3-none-any.whl → 2.3.20__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
polydb/retry.py CHANGED
@@ -3,18 +3,18 @@
3
3
  Retry logic with exponential backoff and metrics hooks
4
4
  """
5
5
 
6
- import functools
7
6
  import time
8
7
  import logging
9
8
  from functools import wraps
10
- from typing import Callable, Optional, Tuple, Type
9
+ from typing import Callable, Tuple, Type
10
+
11
11
  logger = logging.getLogger(__name__)
12
12
 
13
13
  _NON_RETRYABLE_MARKERS = (
14
- "23505", # Postgres unique_violation
15
- "23503", # Postgres foreign_key_violation
16
- "23502", # Postgres not_null_violation
17
- "23514", # Postgres check_violation
14
+ "23505", # Postgres unique_violation
15
+ "23503", # Postgres foreign_key_violation
16
+ "23502", # Postgres not_null_violation
17
+ "23514", # Postgres check_violation
18
18
  "duplicate key value violates",
19
19
  "unique constraint",
20
20
  "UniqueViolation",
@@ -87,8 +87,18 @@ def retry(
87
87
  MetricsHooks.on_query_end(func.__name__, duration, True)
88
88
  return result
89
89
  except exceptions as e:
90
- attempt += 1
91
90
  duration = time.time() - start_time
91
+
92
+ # Permanent errors (unique / FK / not-null / check
93
+ # violations, etc.) are never transient. Fail fast so the
94
+ # caller's insert->update fallthrough fires immediately
95
+ # instead of burning the full backoff window.
96
+ if _is_non_retryable(e):
97
+ MetricsHooks.on_query_end(func.__name__, duration, False)
98
+ MetricsHooks.on_error(func.__name__, e)
99
+ raise
100
+
101
+ attempt += 1
92
102
  MetricsHooks.on_query_end(func.__name__, duration, False)
93
103
  MetricsHooks.on_error(func.__name__, e)
94
104