Skip to content

Conversation

@YuriZmytrakov
Copy link
Collaborator

@YuriZmytrakov YuriZmytrakov commented Oct 28, 2025

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:

  • Code is formatted and linted (run pre-commit run --all-files)
  • Tests pass (run make test)
  • Documentation has been updated to reflect changes, if applicable
  • Changes are added to the changelog

@YuriZmytrakov YuriZmytrakov force-pushed the CAT-1558 branch 2 times, most recently from 3aba909 to 834909a Compare October 28, 2025 11:34
REDIS_DB: int = 15

REDIS_MAX_CONNECTIONS: int = 10
REDIS_MAX_CONNECTIONS: Optional[int] = 10
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should default to None, unless a user specifically wants to block their Redis connections.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to default None.

REDIS_DB: int = 15

REDIS_MAX_CONNECTIONS: int = 10
REDIS_MAX_CONNECTIONS: Optional[int] = 10
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should default to None, unless a user specifically wants to block their Redis connections.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to default None.


REDIS_MAX_CONNECTIONS: int = 10
REDIS_MAX_CONNECTIONS: Optional[int] = 10
REDIS_RETRY_TIMEOUT: bool = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW. you could extract the common fields from these two Pydantic classes into a parent class that both inherit from

if v < 1:
raise ValueError("REDIS_MAX_CONNECTIONS must be at least 1")
return v
def validate_max_connections_sentinel(cls, v: Any) -> Optional[int]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need that validator anymore. Default value is None and it accepts int or None as the type.

Copy link
Collaborator Author

@YuriZmytrakov YuriZmytrakov Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the validation, although it was adding additional validation if the user tried to add max_connection as null, None, or any other incompatible value in the env vars.


@field_validator("REDIS_HEALTH_CHECK_INTERVAL")
@classmethod
def validate_health_check_interval_sentinel(cls, v: int) -> int:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need these validators or the one below. you can just use Field and set a constraint that it should be greater than 0

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add this field as a Field and set it so it's greater than zero
https://docs.pydantic.dev/latest/concepts/fields/

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have replaced the @field_validator with Field to validate the REDIS_HEALTH_CHECK_INTERVAL env var. Moving forward, this much be int greater than 0.

@YuriZmytrakov YuriZmytrakov force-pushed the CAT-1558 branch 2 times, most recently from 53ab6b0 to abfc3be Compare October 28, 2025 12:46
@jonhealy1 jonhealy1 merged commit 5a03393 into stac-utils:main Oct 30, 2025
12 checks passed
@jonhealy1 jonhealy1 mentioned this pull request Oct 30, 2025
4 tasks
jonhealy1 added a commit that referenced this pull request Oct 30, 2025
**Related Issue(s):**

- None

**Description:**

- Ensure `REDIS_MAX_CONNECTION` can accept `None` and integer value for
default number of connection.
[#515](#515)


**PR Checklist:**

- [x] Code is formatted and linted (run `pre-commit run --all-files`)
- [x] Tests pass (run `make test`)
- [x] Documentation has been updated to reflect changes, if applicable
- [x] Changes are added to the changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants