You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
EnvConfigMixin.from_env raises an empty ValueError for absent optional fields #2424
EnvConfigMixin.from_env in src/memos/mem_scheduler/general_modules/misc.py hits a bare raise ValueError() (no message) when a field declared as field: int | None = None has no environment variable set, making any config with plain optional fields impossible to build from the environment:
Summary: Fixed EnvConfigMixin.from_env raising an empty ValueError for absent optional fields (issue #2424). The bug was in src/memos/mem_scheduler/general_modules/misc.py: the loop compared field_info.default is not None, which incorrectly treated a legitimate default=None (as on port: int | None = None) as "no default set" and fell through to raise ValueError(). Also fixed the secondary _parse_env_value bug where Optional[int] annotations kept env vars as raw strings because the type dispatch never unwrapped Union[T, None].
The fix reworks from_env so that required-and-missing fields raise a descriptive ValueError naming the env var, and non-required absent fields are simply omitted from the constructor kwargs — letting pydantic apply the declared default or default_factory uniformly for None, non-None, and factory-produced defaults. _parse_env_value now unwraps both legacy typing.Optional[T] and PEP 604 T | None before dispatching to the bool/int/float branches.
Added 5 regression tests in tests/mem_scheduler/test_config.py: absent optional-None field falls back to default, Optional[int] env var parses as int, required-field missing env var raises with a descriptive message, default_factory field uses the factory, and _parse_env_value unwrap works for both syntaxes. Verified the exact repro from the issue (RabbitMQConfig(EnvConfigMixin, BaseModel) with port: Optional[int] = None) now returns port=None instead of raising.
Test evidence: pytest tests/mem_scheduler/ → 71 passed, 1 skipped; ruff format and ruff check on both changed files → clean.
Base branch:main Branch:bugfix/autodev-2424-20260928140127315 Commit:8f4daf6 PR:#2426 Assigned to:@syzsunshine219 Reviewers:@wustzdy
Activity
Memtensor-AI commentedon Sep 28, 2026
🤖 AutoDev has picked up this issue and started working on it.
Task ID:
2ab67b9f19f05d28Working branch:
bugfix/autodev-2424-20260928140127315Target branch:
latest dev* branchWorkflow: opsp (analysis → coding → testing → PR)
I will post the PR link here once done. If I need more information, I will ask in the comments.
fix(mem_scheduler): EnvConfigMixin.from_env handles optional None def…
Memtensor-AI commentedon Sep 28, 2026
✅ AutoDev task
2ab67b9f19f05d28completed.Summary: Fixed EnvConfigMixin.from_env raising an empty ValueError for absent optional fields (issue #2424). The bug was in src/memos/mem_scheduler/general_modules/misc.py: the loop compared
field_info.default is not None, which incorrectly treated a legitimatedefault=None(as onport: int | None = None) as "no default set" and fell through toraise ValueError(). Also fixed the secondary_parse_env_valuebug whereOptional[int]annotations kept env vars as raw strings because the type dispatch never unwrappedUnion[T, None].The fix reworks
from_envso that required-and-missing fields raise a descriptiveValueErrornaming the env var, and non-required absent fields are simply omitted from the constructor kwargs — letting pydantic apply the declared default ordefault_factoryuniformly forNone, non-None, and factory-produced defaults._parse_env_valuenow unwraps both legacytyping.Optional[T]and PEP 604T | Nonebefore dispatching to the bool/int/float branches.Added 5 regression tests in tests/mem_scheduler/test_config.py: absent optional-None field falls back to default,
Optional[int]env var parses as int, required-field missing env var raises with a descriptive message,default_factoryfield uses the factory, and_parse_env_valueunwrap works for both syntaxes. Verified the exact repro from the issue (RabbitMQConfig(EnvConfigMixin, BaseModel)withport: Optional[int] = None) now returnsport=Noneinstead of raising.Test evidence:
pytest tests/mem_scheduler/→ 71 passed, 1 skipped;ruff formatandruff checkon both changed files → clean.Base branch:
mainBranch:
bugfix/autodev-2424-20260928140127315Commit:
8f4daf6PR: #2426
Assigned to: @syzsunshine219
Reviewers: @wustzdy
fix(mem_scheduler): tolerate absent optional fields in EnvConfigMixin…
github-actions commentedon Oct 31, 2026
This issue has been automatically marked as stale due to inactivity.
fix(mem_scheduler): tolerate absent optional fields in EnvConfigMixin…
github-actions commentedon Nov 8, 2026
This issue has been automatically closed due to inactivity.