From 3273b86b7565181a15809d640bf2ea539b7b63e2 Mon Sep 17 00:00:00 2001 From: profitroll Date: Sun, 6 Aug 2023 12:43:01 +0200 Subject: [PATCH] nested_set raises KeyError if not create_missing --- libbot/sync/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libbot/sync/__init__.py b/libbot/sync/__init__.py index 2553dce..180ba98 100644 --- a/libbot/sync/__init__.py +++ b/libbot/sync/__init__.py @@ -55,7 +55,9 @@ def nested_set(target: dict, value: Any, *path: str, create_missing=True) -> dic elif create_missing: d = d.setdefault(key, {}) else: - return target + raise KeyError( + f"Key '{key}' is not found under path provided ({path}) and create_missing is False" + ) if path[-1] in d or create_missing: d[path[-1]] = value return target