The code iterates on events and then checks event.isDuplicate - out side of the for loop - so its undefined behavior.
As deduplicated events already filtered out few lines later with filter(lambda event: not event.isDuplicate, formatted_events) ), I'm not sure why there is save_if_duplicate as it maybe screws the current alert deduplication mechanism
for event in formatted_events:
event_hash, event_deduplicated = alert_deduplicator.is_deduplicated(event)
event.alert_hash = event_hash
event.isDuplicate = event_deduplicated
if event.isDuplicate and not save_if_duplicate:
logger.info(
"Alert is not saved as a duplicate",
extra={
"provider_type": provider_type,
"num_of_alerts": len(formatted_events),
"provider_id": provider_id,
"tenant_id": tenant_id,
},
)
return None
Looking an this code: https://github.com/keephq/keep/blob/main/keep/api/tasks/process_event_task.py#L188
filter(lambda event: not event.isDuplicate, formatted_events) )
, I'm not sure why there issave_if_duplicate
as it maybe screws the current alert deduplication mechanismif event.isDuplicate and not save_if_duplicate: logger.info( "Alert is not saved as a duplicate", extra={ "provider_type": provider_type, "num_of_alerts": len(formatted_events), "provider_id": provider_id, "tenant_id": tenant_id, }, ) return None