From 31ee8cd45f4156a460e80bf5609739c3053c2105 Mon Sep 17 00:00:00 2001 From: Tal Borenstein Date: Thu, 12 Dec 2024 18:34:47 +0200 Subject: [PATCH] fix: fix --- keep/api/alert_deduplicator/alert_deduplicator.py | 1 + keep/api/core/db.py | 4 ++-- tests/test_deduplications.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/keep/api/alert_deduplicator/alert_deduplicator.py b/keep/api/alert_deduplicator/alert_deduplicator.py index 9ab1ff12a..0ed44c4af 100644 --- a/keep/api/alert_deduplicator/alert_deduplicator.py +++ b/keep/api/alert_deduplicator/alert_deduplicator.py @@ -102,6 +102,7 @@ def _apply_deduplication_rule( "alert_id": alert.id, "fingerprint": alert.fingerprint, "tenant_id": self.tenant_id, + "last_alert_hash_by_fingerprint": last_alert_hash_by_fingerprint, }, ) diff --git a/keep/api/core/db.py b/keep/api/core/db.py index 2a41f3c9b..67f3d7ca9 100644 --- a/keep/api/core/db.py +++ b/keep/api/core/db.py @@ -2110,7 +2110,7 @@ def get_all_deduplication_stats(tenant_id): return stats -def get_last_alert_hash_by_fingerprint(tenant_id, fingerprint): +def get_last_alert_hash_by_fingerprint(tenant_id, fingerprint) -> str | None: # get the last alert for a given fingerprint # to check deduplication with Session(engine) as session: @@ -2121,7 +2121,7 @@ def get_last_alert_hash_by_fingerprint(tenant_id, fingerprint): .limit(1) ) - alert_hash = session.exec(query).first() + alert_hash: str | None = session.scalars(query).first() return alert_hash diff --git a/tests/test_deduplications.py b/tests/test_deduplications.py index 2ec85f006..1fdc60afa 100644 --- a/tests/test_deduplications.py +++ b/tests/test_deduplications.py @@ -276,7 +276,6 @@ def test_custom_deduplication_rule(db_session, client, test_app): assert custom_rule_found -@pytest.mark.timeout(20) @pytest.mark.parametrize( "test_app", [ @@ -321,6 +320,7 @@ def test_custom_deduplication_rule_behaviour(db_session, client, test_app): client.post( "/alerts/event/datadog", json=alert, headers={"x-api-key": "some-api-key"} ) + time.sleep(0.3) deduplication_rules = client.get( "/deduplications", headers={"x-api-key": "some-api-key"}