Skip to content

Commit 504bc6a

Browse files
YuriZmytrakovYuri Zmytrakov
andauthored
fix: ensure max_connection can accept None, Null, empty string (#519)
**Description:** The validator now converts empty strings and null-like values to None, preventing Pydantic validation errors during application startup. **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 a1962b3 commit 504bc6a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

CHANGELOG.md

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

1010
### Added
1111

12+
- Added validator for `REDIS_MAX_CONNECTIONS` to handle empty or null-like values ("", "null", None) and return None instead. [#519](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/519)
13+
1214
### Changed
1315

1416
### Fixed

stac_fastapi/core/stac_fastapi/core/redis_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ 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", mode="before")
40+
@classmethod
41+
def validate_max_connections(cls, v):
42+
"""Handle empty/None values for REDIS_MAX_CONNECTIONS."""
43+
if v in ["", "null", "Null", "NULL", "none", "None", "NONE", None]:
44+
return None
45+
return v
46+
3947
@field_validator("REDIS_SELF_LINK_TTL")
4048
@classmethod
4149
def validate_self_link_ttl_sentinel(cls, v: int) -> int:
@@ -118,6 +126,14 @@ def validate_db_standalone(cls, v: int) -> int:
118126
raise ValueError("REDIS_DB must be a positive integer")
119127
return v
120128

129+
@field_validator("REDIS_MAX_CONNECTIONS", mode="before")
130+
@classmethod
131+
def validate_max_connections(cls, v):
132+
"""Handle empty/None values for REDIS_MAX_CONNECTIONS."""
133+
if v in ["", "null", "Null", "NULL", "none", "None", "NONE", None]:
134+
return None
135+
return v
136+
121137
@field_validator("REDIS_SELF_LINK_TTL")
122138
@classmethod
123139
def validate_self_link_ttl_standalone(cls, v: int) -> int:

0 commit comments

Comments
 (0)