Skip to content

Commit

Permalink
[FIX] Deletion of alerts with new relations
Browse files Browse the repository at this point in the history
  • Loading branch information
whikernel committed Oct 31, 2024
1 parent 0fba01d commit 7895516
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion source/app/blueprints/alerts/alerts_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from app import db
from app.blueprints.case.case_comments import case_comment_update
from app.datamgmt.alerts.alerts_db import get_filtered_alerts, get_alert_by_id, create_case_from_alert, \
register_related_alerts
register_related_alerts, delete_related_alerts_cache
from app.datamgmt.alerts.alerts_db import merge_alert_in_case, unmerge_alert_from_case, cache_similar_alert
from app.datamgmt.alerts.alerts_db import get_related_alerts, get_related_alerts_details
from app.datamgmt.alerts.alerts_db import get_alert_comments, delete_alert_comment, get_alert_comment
Expand Down Expand Up @@ -527,6 +527,9 @@ def alerts_delete_route(alert_id) -> Response:
# Delete the case association
delete_similar_alert_cache(alert_id=alert_id)

# Delete the similarity entries
delete_related_alerts_cache(alert_id=alert_id)

# Delete the alert from the database
db.session.delete(alert)
db.session.commit()
Expand Down
18 changes: 18 additions & 0 deletions source/app/datamgmt/alerts/alerts_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,24 @@ def delete_similar_alert_cache(alert_id):
db.session.commit()


def delete_related_alerts_cache(alert_id):
"""
Delete the related alerts cache
args:
alert_id (int): The ID of the alert
returns:
None
"""
AlertSimilarity.query.filter(
or_(
AlertSimilarity.alert_id == alert_id,
AlertSimilarity.similar_alert_id == alert_id
)
).delete()
db.session.commit()

def delete_similar_alerts_cache(alert_ids: List[int]):
"""
Delete the similar alerts cache
Expand Down

0 comments on commit 7895516

Please sign in to comment.