fix(gateway): null-coalesce mode in SessionResetPolicy.from_dict (#1488)
fix(gateway): null-coalesce mode in SessionResetPolicy.from_dict
This commit is contained in:
commit
6fd9f2a0c5
2 changed files with 10 additions and 1 deletions
|
|
@ -97,10 +97,11 @@ class SessionResetPolicy:
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data: Dict[str, Any]) -> "SessionResetPolicy":
|
def from_dict(cls, data: Dict[str, Any]) -> "SessionResetPolicy":
|
||||||
# Handle both missing keys and explicit null values (YAML null → None)
|
# Handle both missing keys and explicit null values (YAML null → None)
|
||||||
|
mode = data.get("mode")
|
||||||
at_hour = data.get("at_hour")
|
at_hour = data.get("at_hour")
|
||||||
idle_minutes = data.get("idle_minutes")
|
idle_minutes = data.get("idle_minutes")
|
||||||
return cls(
|
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,
|
at_hour=at_hour if at_hour is not None else 4,
|
||||||
idle_minutes=idle_minutes if idle_minutes is not None else 1440,
|
idle_minutes=idle_minutes if idle_minutes is not None else 1440,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,14 @@ class TestSessionResetPolicy:
|
||||||
assert policy.at_hour == 4
|
assert policy.at_hour == 4
|
||||||
assert policy.idle_minutes == 1440
|
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:
|
class TestGatewayConfigRoundtrip:
|
||||||
def test_full_roundtrip(self):
|
def test_full_roundtrip(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue