Skip to content

Commit 0d5bd0e

Browse files
cursoragentarmenzg
andcommitted
fix(autofix): Handle Group.DoesNotExist and None group gracefully
- Add try-except for Group.DoesNotExist in execute() to handle cases where group is deleted between autofix job start and completion webhook - Add None check in _maybe_trigger_supergroups_embedding() to handle edge case where group parameter is None - Both fixes ensure graceful degradation instead of unhandled exceptions Co-authored-by: Armen Zambrano G. <armenzg@users.noreply.github.com>
1 parent 564a21c commit 0d5bd0e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/sentry/seer/autofix/on_completion_hook.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,15 @@ def execute(cls, organization: Organization, run_id: int) -> None:
8282
if group_id is None:
8383
return
8484

85-
group = Group.objects.get(id=group_id, project__organization_id=organization.id)
85+
try:
86+
group = Group.objects.get(id=group_id, project__organization_id=organization.id)
87+
except Group.DoesNotExist:
88+
logger.info(
89+
"autofix.on_completion_hook.group_not_found",
90+
extra={"run_id": run_id, "organization_id": organization.id, "group_id": group_id},
91+
)
92+
return
93+
8694
group.update(seer_explorer_autofix_last_triggered=timezone.now())
8795

8896
# Send webhook for the completed step
@@ -227,13 +235,16 @@ def _maybe_trigger_supergroups_embedding(
227235
organization: Organization,
228236
run_id: int,
229237
state: SeerRunState,
230-
group: Group,
238+
group: Group | None,
231239
) -> None:
232240
"""Trigger supergroups embedding if feature flag is enabled."""
233241
current_step = cls._get_current_step(state)
234242
if current_step != AutofixStep.ROOT_CAUSE:
235243
return
236244

245+
if group is None:
246+
return
247+
237248
if not features.has("projects:supergroup-embeddings-explorer", group.project):
238249
return
239250

0 commit comments

Comments
 (0)