From c7b3b1a529607d59573ef9953a1914602833ab69 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Mon, 23 Sep 2024 17:07:31 -0700 Subject: [PATCH] Fix a condition where default was execting when it shouldn't (#5194) * Fix a condition where default was execting when it shouldn't * Revert cli * Fix commit --------- Co-authored-by: Will Sheldon <114631109+wssheldon@users.noreply.github.com> --- src/dispatch/signal/service.py | 38 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/dispatch/signal/service.py b/src/dispatch/signal/service.py index d7d6bc976c80..2a16953c46d2 100644 --- a/src/dispatch/signal/service.py +++ b/src/dispatch/signal/service.py @@ -654,6 +654,26 @@ def filter_dedup(*, db_session: Session, signal_instance: SignalInstance) -> Sig Returns: SignalInstance: The filtered signal instance. """ + if not signal_instance.signal.filters: + default_dedup_window = datetime.now(timezone.utc) - timedelta(hours=1) + instance = ( + db_session.query(SignalInstance) + .filter( + SignalInstance.signal_id == signal_instance.signal_id, + SignalInstance.created_at >= default_dedup_window, + SignalInstance.id != signal_instance.id, + SignalInstance.case_id.isnot(None), # noqa + ) + .with_entities(SignalInstance.case_id) + .order_by(desc(SignalInstance.created_at)) + .first() + ) + + if instance: + signal_instance.case_id = instance.case_id + signal_instance.filter_action = SignalFilterAction.deduplicate + return signal_instance + for f in signal_instance.signal.filters: if f.mode != SignalFilterMode.active: continue @@ -683,24 +703,6 @@ def filter_dedup(*, db_session: Session, signal_instance: SignalInstance) -> Sig signal_instance.case_id = instances[0].case_id signal_instance.filter_action = SignalFilterAction.deduplicate break - # apply default deduplication rule - else: - default_dedup_window = datetime.now(timezone.utc) - timedelta(hours=1) - instance = ( - db_session.query(SignalInstance) - .filter( - SignalInstance.signal_id == signal_instance.signal_id, - SignalInstance.created_at >= default_dedup_window, - SignalInstance.id != signal_instance.id, - SignalInstance.case_id.isnot(None), # noqa - ) - .with_entities(SignalInstance.case_id) - .order_by(desc(SignalInstance.created_at)) - .first() - ) - if instance: - signal_instance.case_id = instance.case_id - signal_instance.filter_action = SignalFilterAction.deduplicate return signal_instance