From 9286ed6271a336613d741e3a6340ccec89fc9d04 Mon Sep 17 00:00:00 2001 From: Robert Szefler Date: Mon, 4 Dec 2023 16:45:56 +0100 Subject: [PATCH] fix pydantic/_thread.lock interaction errors --- src/robusta/core/playbooks/base_trigger.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/robusta/core/playbooks/base_trigger.py b/src/robusta/core/playbooks/base_trigger.py index 8166f9820..2a9373077 100644 --- a/src/robusta/core/playbooks/base_trigger.py +++ b/src/robusta/core/playbooks/base_trigger.py @@ -21,8 +21,12 @@ def get_event_description(self) -> str: class BaseTrigger(DocumentedModel): - # TODO what should the pool size be? - executor = ProcessPoolExecutor(max_workers=1) + def __new__(cls, *args, **kwargs): + # Perform any pydantic-related class building code before creating the + # executor. Otherwise obscure errors related to pickling _thread.lock ensue. + cls = super().__new__(cls) + # TODO what should the pool size be? + cls._executor = ProcessPoolExecutor(max_workers=1) def get_trigger_event(self) -> str: pass @@ -33,7 +37,7 @@ def should_fire(self, event: TriggerEvent, playbook_id: str): def build_execution_event( self, event: TriggerEvent, sink_findings: Dict[str, List[Finding]] ) -> Optional[ExecutionBaseEvent]: - return BaseTrigger.executor.submit(self._build_execution_event, event, sink_findings) + return BaseTrigger._executor.submit(self._build_execution_event, event, sink_findings) def _build_execution_event( self, event: TriggerEvent, sink_findings: Dict[str, List[Finding]]