refactor: one definition of a followed channel and of a choice spelling

The explore purge rebuilt followed_channel's two EXISTS clauses inline, so what is polled and what may be deleted could drift; it now uses the predicate, which moved to sync/explore.py. The env validator and sysconfig each folded a choice value on their own; both call config.canonical_choice. The deep-backfill comment no longer calls recent backfill unconditional.
This commit is contained in:
2026-09-17 03:53:29 +02:00
parent 86bc008a81
commit 4bfba4aa86
5 changed files with 40 additions and 32 deletions
+9 -2
View File
@@ -40,6 +40,14 @@ def choices_of(annotation: object) -> tuple[str, ...]:
return tuple(get_args(annotation)) if get_origin(annotation) is Literal else ()
def canonical_choice(options: tuple[str, ...], raw: object) -> str | None:
"""The option `raw` names, in its canonical spelling (any letter case, surrounding space
ignored), or None. The ONE matching rule for a choice value from the env and from the admin
API, so a spelling one accepts the other cannot refuse."""
folded = str(raw).strip().casefold()
return next((option for option in options if option.casefold() == folded), None)
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
@@ -370,8 +378,7 @@ class Settings(BaseSettings):
field = cls.model_fields.get(info.field_name or "")
options = choices_of(field.annotation) if field else ()
if options and isinstance(value, str):
folded = value.strip().casefold()
return next((o for o in options if o.casefold() == folded), value)
return canonical_choice(options, value) or value
return value
@model_validator(mode="after")