diff --git a/keep/api/core/db.py b/keep/api/core/db.py index 2146efa8ed..b452fb8452 100644 --- a/keep/api/core/db.py +++ b/keep/api/core/db.py @@ -1395,15 +1395,20 @@ def batch_enrich( } # Prepare bulk update for existing enrichments - to_update = [] to_create = [] audit_entries = [] for fingerprint in fingerprints: existing = existing_enrichments.get(fingerprint) - if existing: - to_update.append(existing.id) + # AlertEnrichment exist, update and merge enrichments + new_enrichment_data = {**existing.enrichments, **enrichments} + stmt = ( + update(AlertEnrichment) + .where(AlertEnrichment.id == existing.id) + .values(enrichments=new_enrichment_data) + ) + session.execute(stmt) else: # For new entries to_create.append( @@ -1425,15 +1430,6 @@ def batch_enrich( ) ) - # Bulk update in a single query - if to_update: - stmt = ( - update(AlertEnrichment) - .where(AlertEnrichment.id.in_(to_update)) - .values(enrichments=enrichments) - ) - session.execute(stmt) - # Bulk insert new enrichments if to_create: session.add_all(to_create) diff --git a/pyproject.toml b/pyproject.toml index b91d2f24bd..8a2c40bb2f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "keep" -version = "0.47.1" +version = "0.47.2" description = "Alerting. for developers, by developers." authors = ["Keep Alerting LTD"] packages = [{include = "keep"}]