diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b2bf700..554b1a3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added +- 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) + ### Changed ### Fixed diff --git a/stac_fastapi/core/stac_fastapi/core/redis_utils.py b/stac_fastapi/core/stac_fastapi/core/redis_utils.py index 6cfc00b6..f1e3fe74 100644 --- a/stac_fastapi/core/stac_fastapi/core/redis_utils.py +++ b/stac_fastapi/core/stac_fastapi/core/redis_utils.py @@ -36,6 +36,14 @@ def validate_db_sentinel(cls, v: int) -> int: raise ValueError("REDIS_DB must be a positive integer") return v + @field_validator("REDIS_MAX_CONNECTIONS", mode="before") + @classmethod + def validate_max_connections(cls, v): + """Handle empty/None values for REDIS_MAX_CONNECTIONS.""" + if v in ["", "null", "Null", "NULL", "none", "None", "NONE", None]: + return None + return v + @field_validator("REDIS_SELF_LINK_TTL") @classmethod def validate_self_link_ttl_sentinel(cls, v: int) -> int: @@ -118,6 +126,14 @@ def validate_db_standalone(cls, v: int) -> int: raise ValueError("REDIS_DB must be a positive integer") return v + @field_validator("REDIS_MAX_CONNECTIONS", mode="before") + @classmethod + def validate_max_connections(cls, v): + """Handle empty/None values for REDIS_MAX_CONNECTIONS.""" + if v in ["", "null", "Null", "NULL", "none", "None", "NONE", None]: + return None + return v + @field_validator("REDIS_SELF_LINK_TTL") @classmethod def validate_self_link_ttl_standalone(cls, v: int) -> int: