From 102a25557502c1c11eb3cd4794d20587882c3902 Mon Sep 17 00:00:00 2001 From: teknium1 Date: Sun, 15 Mar 2026 21:40:22 -0700 Subject: [PATCH] fix(gateway): null-coalesce mode in SessionResetPolicy.from_dict Complete the YAML null handling for all three SessionResetPolicy fields. at_hour and idle_minutes already had null coalescing; mode was still using data.get('mode', 'both') which returns None when the key exists with an explicit null value. Add regression test covering all-null input. Based on PR #1120 by stablegenius49. --- gateway/config.py | 3 ++- tests/gateway/test_config.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gateway/config.py b/gateway/config.py index 2b187c521..0cf8fdfa9 100644 --- a/gateway/config.py +++ b/gateway/config.py @@ -97,10 +97,11 @@ class SessionResetPolicy: @classmethod def from_dict(cls, data: Dict[str, Any]) -> "SessionResetPolicy": # Handle both missing keys and explicit null values (YAML null → None) + mode = data.get("mode") at_hour = data.get("at_hour") idle_minutes = data.get("idle_minutes") return cls( - mode=data.get("mode", "both"), + mode=mode if mode is not None else "both", at_hour=at_hour if at_hour is not None else 4, idle_minutes=idle_minutes if idle_minutes is not None else 1440, ) diff --git a/tests/gateway/test_config.py b/tests/gateway/test_config.py index c604ee521..d23147d81 100644 --- a/tests/gateway/test_config.py +++ b/tests/gateway/test_config.py @@ -83,6 +83,14 @@ class TestSessionResetPolicy: assert policy.at_hour == 4 assert policy.idle_minutes == 1440 + def test_from_dict_treats_null_values_as_defaults(self): + restored = SessionResetPolicy.from_dict( + {"mode": None, "at_hour": None, "idle_minutes": None} + ) + assert restored.mode == "both" + assert restored.at_hour == 4 + assert restored.idle_minutes == 1440 + class TestGatewayConfigRoundtrip: def test_full_roundtrip(self):