Skip to content

Commit 458b086

Browse files
committed
postgres settings
1 parent 638c2bc commit 458b086

File tree

2 files changed

+46
-35
lines changed

2 files changed

+46
-35
lines changed
Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Annotated
2+
13
from pydantic import Field
24

35
from .base import BaseCustomSettings
@@ -6,26 +8,32 @@
68
class ClientRequestSettings(BaseCustomSettings):
79
# NOTE: These entries are used in some old services as well. These need to be updated if these
810
# variable names or defaults are changed.
9-
HTTP_CLIENT_REQUEST_TOTAL_TIMEOUT: int | None = Field(
10-
default=20,
11-
description="timeout in seconds used for outgoing http requests",
12-
)
11+
HTTP_CLIENT_REQUEST_TOTAL_TIMEOUT: Annotated[
12+
int | None,
13+
Field(
14+
description="timeout in seconds used for outgoing http requests",
15+
),
16+
] = 20
1317

14-
HTTP_CLIENT_REQUEST_AIOHTTP_CONNECT_TIMEOUT: int | None = Field(
15-
default=None,
16-
description=(
17-
"Maximal number of seconds for acquiring a connection"
18-
" from pool. The time consists connection establishment"
19-
" for a new connection or waiting for a free connection"
20-
" from a pool if pool connection limits are exceeded. "
21-
"For pure socket connection establishment time use sock_connect."
18+
HTTP_CLIENT_REQUEST_AIOHTTP_CONNECT_TIMEOUT: Annotated[
19+
int | None,
20+
Field(
21+
description=(
22+
"Maximal number of seconds for acquiring a connection"
23+
" from pool. The time consists connection establishment"
24+
" for a new connection or waiting for a free connection"
25+
" from a pool if pool connection limits are exceeded. "
26+
"For pure socket connection establishment time use sock_connect."
27+
),
2228
),
23-
)
29+
] = None
2430

25-
HTTP_CLIENT_REQUEST_AIOHTTP_SOCK_CONNECT_TIMEOUT: int | None = Field(
26-
default=5,
27-
description=(
28-
"aiohttp specific field used in ClientTimeout, timeout for connecting to a "
29-
"peer for a new connection not given a pool"
31+
HTTP_CLIENT_REQUEST_AIOHTTP_SOCK_CONNECT_TIMEOUT: Annotated[
32+
int | None,
33+
Field(
34+
description=(
35+
"aiohttp specific field used in ClientTimeout, timeout for connecting to a "
36+
"peer for a new connection not given a pool"
37+
),
3038
),
31-
)
39+
] = 5

packages/settings-library/src/settings_library/postgres.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from functools import cached_property
2+
from typing import Annotated
23
from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse
34

45
from pydantic import (
@@ -25,26 +26,28 @@ class PostgresSettings(BaseCustomSettings):
2526
POSTGRES_PASSWORD: SecretStr
2627

2728
# database
28-
POSTGRES_DB: str = Field(..., description="Database name")
29+
POSTGRES_DB: Annotated[str, Field(description="Database name")]
2930

3031
# pool connection limits
31-
POSTGRES_MINSIZE: int = Field(
32-
default=1, description="Minimum number of connections in the pool", ge=1
33-
)
34-
POSTGRES_MAXSIZE: int = Field(
35-
default=50, description="Maximum number of connections in the pool", ge=1
36-
)
32+
POSTGRES_MINSIZE: Annotated[
33+
int, Field(description="Minimum number of connections in the pool", ge=1)
34+
] = 1
35+
POSTGRES_MAXSIZE: Annotated[
36+
int, Field(description="Maximum number of connections in the pool", ge=1)
37+
] = 50
3738

38-
POSTGRES_CLIENT_NAME: str | None = Field(
39-
default=None,
40-
description="Name of the application connecting the postgres database, will default to use the host hostname (hostname on linux)",
41-
validation_alias=AliasChoices(
42-
"POSTGRES_CLIENT_NAME",
43-
# This is useful when running inside a docker container, then the hostname is set each client gets a different name
44-
"HOST",
45-
"HOSTNAME",
39+
POSTGRES_CLIENT_NAME: Annotated[
40+
str | None,
41+
Field(
42+
description="Name of the application connecting the postgres database, will default to use the host hostname (hostname on linux)",
43+
validation_alias=AliasChoices(
44+
"POSTGRES_CLIENT_NAME",
45+
# This is useful when running inside a docker container, then the hostname is set each client gets a different name
46+
"HOST",
47+
"HOSTNAME",
48+
),
4649
),
47-
)
50+
] = None
4851

4952
@field_validator("POSTGRES_MAXSIZE")
5053
@classmethod

0 commit comments

Comments
 (0)