Skip to content

Commit b4f9c10

Browse files
committed
Use deepmerge to merge handler configs instead of just updating dict
1 parent 1d5d716 commit b4f9c10

File tree

1 file changed

+20
-4
lines changed
  • finecode_extension_runner/src/finecode_extension_runner/_services

1 file changed

+20
-4
lines changed

finecode_extension_runner/src/finecode_extension_runner/_services/run_action.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import time
66
import typing
77

8+
import deepmerge
89
from loguru import logger
910
from pydantic.dataclasses import dataclass as pydantic_dataclass
1011

@@ -19,7 +20,17 @@
1920

2021
last_run_id: int = 0
2122
partial_result_sender: partial_result_sender_module.PartialResultSender
22-
23+
handler_config_merger = deepmerge.Merger(
24+
[
25+
(list, ["override"]),
26+
(dict, ["merge"]),
27+
(set, ["override"])
28+
],
29+
# all other types:
30+
["override"],
31+
# strategies in the case where the types conflict:
32+
["override"]
33+
)
2334

2435
class ActionFailedException(Exception):
2536
def __init__(self, message: str) -> None:
@@ -401,10 +412,14 @@ async def execute_action_handler(
401412
handler.source, None
402413
)
403414
handler_raw_config = {}
404-
# TODO: deep merge instead?
405415
if handler_global_config is not None:
406-
handler_raw_config.update(handler_global_config)
407-
handler_raw_config.update(handler.config)
416+
handler_raw_config = handler_global_config
417+
if handler_raw_config == {}:
418+
# still empty, just assign
419+
handler_raw_config = handler.config
420+
else:
421+
# not empty anymore, deep merge
422+
handler_config_merger.merge(handler_raw_config, handler.config)
408423

409424
def get_handler_config(param_type):
410425
# TODO: validation errors
@@ -564,6 +579,7 @@ async def run_subresult_coros_sequentially(
564579
try:
565580
coro_result = await coro
566581
except Exception as e:
582+
logger.error(f"Unhandled exception in subresult coroutine({action_name}, run {run_id}):")
567583
logger.exception(e)
568584
raise ActionFailedException(
569585
f"Running action handlers of '{action_name}' failed(Run {run_id}): {e}"

0 commit comments

Comments
 (0)