Skip to content

Commit 5a03393

Browse files
YuriZmytrakovYuri Zmytrakov
andauthored
fix: ensure max_connection accepts default/None (stac-utils#515)
**Description:** This PR updates the handling of the `max_connection` parameter so that it correctly accepts `None` as the default or integer values. Previously, only integer values were allowed, which caused errors when the parameter was unset or set as None. **PR Checklist:** - [x] Code is formatted and linted (run `pre-commit run --all-files`) - [x] Tests pass (run `make test`) - [ ] Documentation has been updated to reflect changes, if applicable - [x] Changes are added to the changelog Co-authored-by: Yuri Zmytrakov <[email protected]>
1 parent f834a9e commit 5a03393

File tree

2 files changed

+7
-37
lines changed

2 files changed

+7
-37
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313

1414
### Fixed
1515

16+
- Ensure `REDIS_MAX_CONNECTION` can accept `None` and integer value for default number of connection. [#515](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/515)
17+
1618
### Removed
1719

1820
### Updated

stac_fastapi/core/stac_fastapi/core/redis_utils.py

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import List, Optional, Tuple
66
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse
77

8-
from pydantic import field_validator
8+
from pydantic import Field, field_validator
99
from pydantic_settings import BaseSettings
1010
from redis import asyncio as aioredis
1111
from redis.asyncio.sentinel import Sentinel
@@ -21,11 +21,11 @@ class RedisSentinelSettings(BaseSettings):
2121
REDIS_SENTINEL_MASTER_NAME: str = "master"
2222
REDIS_DB: int = 15
2323

24-
REDIS_MAX_CONNECTIONS: int = 10
24+
REDIS_MAX_CONNECTIONS: Optional[int] = None
2525
REDIS_RETRY_TIMEOUT: bool = True
2626
REDIS_DECODE_RESPONSES: bool = True
2727
REDIS_CLIENT_NAME: str = "stac-fastapi-app"
28-
REDIS_HEALTH_CHECK_INTERVAL: int = 30
28+
REDIS_HEALTH_CHECK_INTERVAL: int = Field(default=30, gt=0)
2929
REDIS_SELF_LINK_TTL: int = 1800
3030

3131
@field_validator("REDIS_DB")
@@ -36,22 +36,6 @@ def validate_db_sentinel(cls, v: int) -> int:
3636
raise ValueError("REDIS_DB must be a positive integer")
3737
return v
3838

39-
@field_validator("REDIS_MAX_CONNECTIONS")
40-
@classmethod
41-
def validate_max_connections_sentinel(cls, v: int) -> int:
42-
"""Validate REDIS_MAX_CONNECTIONS is at least 1."""
43-
if v < 1:
44-
raise ValueError("REDIS_MAX_CONNECTIONS must be at least 1")
45-
return v
46-
47-
@field_validator("REDIS_HEALTH_CHECK_INTERVAL")
48-
@classmethod
49-
def validate_health_check_interval_sentinel(cls, v: int) -> int:
50-
"""Validate REDIS_HEALTH_CHECK_INTERVAL is not negative integer."""
51-
if v < 0:
52-
raise ValueError("REDIS_HEALTH_CHECK_INTERVAL must be a positive integer")
53-
return v
54-
5539
@field_validator("REDIS_SELF_LINK_TTL")
5640
@classmethod
5741
def validate_self_link_ttl_sentinel(cls, v: int) -> int:
@@ -111,11 +95,11 @@ class RedisSettings(BaseSettings):
11195
REDIS_PORT: int = 6379
11296
REDIS_DB: int = 15
11397

114-
REDIS_MAX_CONNECTIONS: int = 10
98+
REDIS_MAX_CONNECTIONS: Optional[int] = None
11599
REDIS_RETRY_TIMEOUT: bool = True
116100
REDIS_DECODE_RESPONSES: bool = True
117101
REDIS_CLIENT_NAME: str = "stac-fastapi-app"
118-
REDIS_HEALTH_CHECK_INTERVAL: int = 30
102+
REDIS_HEALTH_CHECK_INTERVAL: int = Field(default=30, gt=0)
119103
REDIS_SELF_LINK_TTL: int = 1800
120104

121105
@field_validator("REDIS_PORT")
@@ -134,22 +118,6 @@ def validate_db_standalone(cls, v: int) -> int:
134118
raise ValueError("REDIS_DB must be a positive integer")
135119
return v
136120

137-
@field_validator("REDIS_MAX_CONNECTIONS")
138-
@classmethod
139-
def validate_max_connections_standalone(cls, v: int) -> int:
140-
"""Validate REDIS_MAX_CONNECTIONS is at least 1."""
141-
if v < 1:
142-
raise ValueError("REDIS_MAX_CONNECTIONS must be at least 1")
143-
return v
144-
145-
@field_validator("REDIS_HEALTH_CHECK_INTERVAL")
146-
@classmethod
147-
def validate_health_check_interval_standalone(cls, v: int) -> int:
148-
"""Validate REDIS_HEALTH_CHECK_INTERVAL is not a negative."""
149-
if v < 0:
150-
raise ValueError("REDIS_HEALTH_CHECK_INTERVAL must be a positive integer")
151-
return v
152-
153121
@field_validator("REDIS_SELF_LINK_TTL")
154122
@classmethod
155123
def validate_self_link_ttl_standalone(cls, v: int) -> int:

0 commit comments

Comments
 (0)