Skip to content

Commit b6076b6

Browse files
authored
Stability fixes (#453)
* attempt better stability fixes * hide input in errors * Bump version
1 parent 1854afb commit b6076b6

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "dapla-toolbelt-pseudo"
3-
version = "4.2.2"
3+
version = "4.3.0"
44
description = "Pseudonymization extensions for Dapla"
55
authors = ["Dapla Developers <dapla-platform-developers@ssb.no>"]
66
license = "MIT"

src/dapla_pseudo/v1/client.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
import google.auth.transport.requests
1212
import google.oauth2.id_token
1313
import requests
14+
from aiohttp import ClientPayloadError
1415
from aiohttp import ClientResponse
1516
from aiohttp import ClientSession
1617
from aiohttp import ClientTimeout
18+
from aiohttp import ServerDisconnectedError
1719
from aiohttp import TCPConnector
1820
from aiohttp_retry import ExponentialRetry
1921
from aiohttp_retry import RetryClient
@@ -129,7 +131,7 @@ async def _post(
129131

130132
split_pseudo_requests = self._split_requests(pseudo_requests)
131133
aio_session = ClientSession(
132-
connector=TCPConnector(limit=200, force_close=True),
134+
connector=TCPConnector(limit=100, enable_cleanup_closed=True),
133135
timeout=ClientTimeout(total=TIMEOUT_DEFAULT),
134136
)
135137
async with RetryClient(
@@ -139,11 +141,15 @@ async def _post(
139141
start_timeout=0.1,
140142
max_timeout=30,
141143
factor=6,
142-
statuses={
143-
400,
144-
}.union(
144+
statuses={400, 429}.union(
145145
set(range(500, 600))
146146
), # Retry all 5xx errors and 400 Bad Request
147+
exceptions={
148+
ClientPayloadError,
149+
ServerDisconnectedError,
150+
asyncio.TimeoutError,
151+
OSError,
152+
},
147153
),
148154
) as client:
149155
results = await asyncio.gather(
@@ -159,7 +165,7 @@ async def _post(
159165
for req in reqs
160166
]
161167
)
162-
await asyncio.sleep(0.1) # Allow time for sockets to close
168+
await asyncio.sleep(0.5) # Allow time for sockets to close
163169
await aio_session.close()
164170

165171
return PseudoClient._merge_responses(results)

src/dapla_pseudo/v1/models/api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from dataclasses import dataclass
66

77
import polars as pl
8+
from pydantic import ConfigDict
89

910
from dapla_pseudo.models import APIModel
1011
from dapla_pseudo.v1.models.core import PseudoFunction
@@ -14,6 +15,8 @@
1415
class PseudoFieldRequest(APIModel):
1516
"""Model of the pseudo field request sent to the service."""
1617

18+
model_config = ConfigDict(hide_input_in_errors=True)
19+
1720
pseudo_func: PseudoFunction
1821
name: str
1922
pattern: str
@@ -24,6 +27,8 @@ class PseudoFieldRequest(APIModel):
2427
class DepseudoFieldRequest(APIModel):
2528
"""Model of the depseudo field request sent to the service."""
2629

30+
model_config = ConfigDict(hide_input_in_errors=True)
31+
2732
pseudo_func: PseudoFunction
2833
name: str
2934
pattern: str
@@ -34,6 +39,8 @@ class DepseudoFieldRequest(APIModel):
3439
class RepseudoFieldRequest(APIModel):
3540
"""Model of the repseudo field request sent to the service."""
3641

42+
model_config = ConfigDict(hide_input_in_errors=True)
43+
3744
source_pseudo_func: PseudoFunction
3845
target_pseudo_func: PseudoFunction | None
3946
name: str

0 commit comments

Comments
 (0)