Repository navigation
Conversation
from_env crashed with a bare, message-less ValueError() when a field declared with default None had no environment variable, so any config with a plain optional field (e.g. RabbitMQConfig) could not be built from the environment at all. Absent optional fields are now simply omitted so pydantic applies the model default. Additionally, _parse_env_value unwraps Optional[X] / X | None annotations so an optional int or float env var parses as its inner type. Red/green verified: the new tests fail against the old implementation (empty ValueError) and pass with the fix. Signed-off-by: simpleqt <89645338+simpleqt@users.noreply.github.com>
🤖 Open Code ReviewTarget: PR #2425 🔍 OpenCodeReview found 2 issue(s) in this PR. 1.
|
✅ Automated Test Results: PASSEDAll tests passed (3/3 executed). memos_python_core/changed-repo-python: 3/3. Duration: 9s [advisory, non-gating] AI-generated tests on branch test/auto-gen-af001f99020e3d90-20260928220654: 120/120 passed — these do NOT affect the PR verdict; review the branch manually. Branch: |
|
This PR has been automatically marked as stale due to inactivity. |
|
This PR has been automatically closed due to inactivity. |
Description
Fixes #2424
EnvConfigMixin.from_envcrashed with a bareraise ValueError()(empty message) whenever a field declared withdefault = Nonehad no environment variable — so a config as ordinary asport: Optional[int] = Nonecould not be built from the environment at all. This is on the scheduler init path (memos/configs/mem_scheduler.py→RabbitMQConfig.from_env()).Implementation:
elif field_info.default is not None/else: raise ValueError()pair is gone)_parse_env_valueunwrapsOptional[X]/X | Noneviatyping.get_args, so an optionalint/floatenv var parses as its inner type instead of staying a raw stringNo dependency changes.
Type of change
How Has Been Tested?
New
tests/mem_scheduler/test_env_config_mixin.pycovers: absent optional fields fall back to defaults (red/green discriminator — crashed with the emptyValueErroron main),Optional[int]parsing tointand bool parsing, and that genuinely required fields still raise the named error.ruff check --no-fixreports no new findings versusmainon the touched source file (the six it lists there are pre-existing).Checklist