feat(seer): Clear Seer automation handoff preferences on integration deletion#113337
feat(seer): Clear Seer automation handoff preferences on integration deletion#113337
Conversation
| project_id | ||
| for project_id, handoff_integration_id in project_handoff_integration_ids | ||
| if handoff_integration_id == integration_id | ||
| ] |
There was a problem hiding this comment.
This fn can be greatly simplified once we finish the settings migration. We can skip straight from here to L195.
For now, we have to get all project preferences for this org, because reading from Seer doesn't allow us to know which projects are affected beforehand.
Backend Test FailuresFailures on
|
Backend Test FailuresFailures on
|
| candidate_project_ids = [ | ||
| project_id | ||
| for project_id, handoff_integration_id in project_handoff_integration_ids | ||
| if handoff_integration_id == integration_id |
There was a problem hiding this comment.
Bug: The comparison handoff_integration_id == integration_id may fail due to a type mismatch, as handoff_integration_id could be a string while integration_id is an integer.
Severity: MEDIUM
Suggested Fix
Ensure type consistency before the comparison. Cast handoff_integration_id to an integer, for example by changing the comparison to int(handoff_integration_id) == integration_id. This will guarantee that the comparison is between two integers.
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/tasks/seer/cleanup.py#L152
Potential issue: In the cleanup task, `project_handoff_integration_ids` are retrieved
using `values_list()` on a `LegacyTextJSONField`. It is possible that `values_list()`
returns the raw string value from the database (e.g., `"123"`) instead of a deserialized
integer. This would cause the comparison `handoff_integration_id == integration_id` to
always evaluate to false, as it would be comparing a string to an integer. Consequently,
no projects would be selected for cleanup, causing the task to fail silently when the
`organizations:seer-project-settings-read-from-sentry` feature flag is enabled.
Did we get this right? 👍 / 👎 to inform future reviews.
Fixes AIML-2771
When an OrganizationIntegration is deleted, any project preferences that reference it via automation_handoff are left with a dangling integration_id, and cleared the next time autofix tries to access it and throws IntegrationNotFound.
Here we add a task that fires on integration deletion and clears the handoff from all affected project preferences. A Seer API failure leaves both the Sentry DB and Seer DB in sync.