Skip to content

Commit

Permalink
Fix a condition where default was execting when it shouldn't (#5194)
Browse files Browse the repository at this point in the history
* Fix a condition where default was execting when it shouldn't

* Revert cli

* Fix commit

---------

Co-authored-by: Will Sheldon <[email protected]>
  • Loading branch information
kevgliss and wssheldon authored Sep 24, 2024
1 parent 2902f9a commit c7b3b1a
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/dispatch/signal/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit c7b3b1a

Please sign in to comment.