fix(aci): Make associate_new_group_with_detector more robust#103418
fix(aci): Make associate_new_group_with_detector more robust#103418
Conversation
| }, | ||
| ) | ||
| return False | ||
|
|
There was a problem hiding this comment.
Bug: Detector.get_error_detector_for_project() lacks error handling, causing Detector.DoesNotExist to crash the function if no detector is found.
Severity: CRITICAL | Confidence: 0.95
🔍 Detailed Analysis
The code at src/sentry/workflow_engine/processors/detector.py lines 382-384 calls Detector.get_error_detector_for_project(group.project.id).id without error handling. The get_error_detector_for_project() method uses Django's .get(), which raises Detector.DoesNotExist if no matching detector is found for a project. This unhandled exception will crash the associate_new_group_with_detector() function if an error detector is missing for a project, leading to unexpected failures in the workflow engine.
💡 Suggested Fix
Wrap the call to Detector.get_error_detector_for_project() in a try-except Detector.DoesNotExist block. If the exception occurs, set detector_id = None to gracefully handle the missing detector, similar to how it's handled later in the function.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/sentry/workflow_engine/processors/detector.py#L382-L385
Potential issue: The code at `src/sentry/workflow_engine/processors/detector.py` lines
382-384 calls `Detector.get_error_detector_for_project(group.project.id).id` without
error handling. The `get_error_detector_for_project()` method uses Django's `.get()`,
which raises `Detector.DoesNotExist` if no matching detector is found for a project.
This unhandled exception will crash the `associate_new_group_with_detector()` function
if an error detector is missing for a project, leading to unexpected failures in the
workflow engine.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference_id: 2701266
Since we know Detectors can go away (even before we have a chance to process a new occurrence) and we have a convention for representing that with DetectorGroup, update associate_new_group_with_detector accordingly.