From d5b64ccec9672da9e7c4b09518cf3302338ffd1d Mon Sep 17 00:00:00 2001 From: Barry <91018388+barry166@users.noreply.github.com> Date: Mon, 29 Jun 2026 17:17:32 +0800 Subject: [PATCH] fix(cli): reject invalid int config values without traceback (#5956) --- cli/python/src/mem0_cli/config.py | 5 ++++- cli/python/tests/test_config.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cli/python/src/mem0_cli/config.py b/cli/python/src/mem0_cli/config.py index 0d8de27b9..cc513ce4d 100644 --- a/cli/python/src/mem0_cli/config.py +++ b/cli/python/src/mem0_cli/config.py @@ -235,7 +235,10 @@ def set_nested_value(config: Mem0Config, dotted_key: str, value: str) -> bool: if isinstance(current, bool): value = value.lower() in ("true", "1", "yes") # type: ignore[assignment] elif isinstance(current, int): - value = int(value) # type: ignore[assignment] + try: + value = int(value) # type: ignore[assignment] + except ValueError: + return False setattr(obj, final_key, value) return True diff --git a/cli/python/tests/test_config.py b/cli/python/tests/test_config.py index 86dc2561b..051bd3167 100644 --- a/cli/python/tests/test_config.py +++ b/cli/python/tests/test_config.py @@ -139,6 +139,11 @@ class TestNestedAccess: assert set_nested_value(config, "platform.api_key", "new-key") assert config.platform.api_key == "new-key" + def test_set_int_value_rejects_invalid_input(self): + config = Mem0Config() + assert set_nested_value(config, "version", "abc") is False + assert config.version == 1 + def test_set_nonexistent_key(self): config = Mem0Config() assert set_nested_value(config, "nonexistent.key", "val") is False