Skip to content

Commit 564a21c

Browse files
committed
remove None type from group
1 parent 4f0e02a commit 564a21c

File tree

1 file changed

+7
-35
lines changed

1 file changed

+7
-35
lines changed

src/sentry/seer/autofix/on_completion_hook.py

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,10 @@ def execute(cls, organization: Organization, run_id: int) -> None:
8080

8181
group_id = state.metadata.get("group_id") if state.metadata else None
8282
if group_id is None:
83-
group = None
84-
else:
85-
try:
86-
group = Group.objects.get(id=group_id, project__organization_id=organization.id)
87-
except Group.DoesNotExist:
88-
group = None
83+
return
84+
85+
group = Group.objects.get(id=group_id, project__organization_id=organization.id)
86+
group.update(seer_explorer_autofix_last_triggered=timezone.now())
8987

9088
# Send webhook for the completed step
9189
cls._send_step_webhook(organization, run_id, state, group)
@@ -95,9 +93,6 @@ def execute(cls, organization: Organization, run_id: int) -> None:
9593
# Continue the automated pipeline if stopping_point hasn't been reached
9694
cls._maybe_continue_pipeline(organization, run_id, state, group)
9795

98-
if group is not None:
99-
group.update(seer_explorer_autofix_last_triggered=timezone.now())
100-
10196
@classmethod
10297
def find_latest_artifact_for_step(cls, state: SeerRunState, key: str) -> Artifact | None:
10398
for block in reversed(state.blocks):
@@ -114,16 +109,13 @@ def _send_step_webhook(
114109
organization: Organization,
115110
run_id: int,
116111
state: SeerRunState,
117-
group: Group | None,
112+
group: Group,
118113
):
119114
"""
120115
Send webhook for the completed step.
121116
122117
Determines which step just completed and sends the appropriate webhook event.
123118
"""
124-
if group is None:
125-
return
126-
127119
current_step = cls._get_current_step(state)
128120

129121
webhook_payload = {
@@ -235,21 +227,13 @@ def _maybe_trigger_supergroups_embedding(
235227
organization: Organization,
236228
run_id: int,
237229
state: SeerRunState,
238-
group: Group | None,
230+
group: Group,
239231
) -> None:
240232
"""Trigger supergroups embedding if feature flag is enabled."""
241233
current_step = cls._get_current_step(state)
242234
if current_step != AutofixStep.ROOT_CAUSE:
243235
return
244236

245-
if group is None:
246-
group_id = state.metadata.get("group_id") if state.metadata else None
247-
logger.warning(
248-
"autofix.supergroup_embedding.group_not_found",
249-
extra={"group_id": group_id},
250-
)
251-
return
252-
253237
if not features.has("projects:supergroup-embeddings-explorer", group.project):
254238
return
255239

@@ -307,7 +291,7 @@ def _maybe_continue_pipeline(
307291
organization: Organization,
308292
run_id: int,
309293
state: SeerRunState,
310-
group: Group | None,
294+
group: Group,
311295
) -> None:
312296
"""
313297
Continue to the next step if stopping_point hasn't been reached.
@@ -327,18 +311,6 @@ def _maybe_continue_pipeline(
327311

328312
stopping_point = AutofixStoppingPoint(metadata["stopping_point"])
329313

330-
if group is None:
331-
group_id = state.metadata.get("group_id") if state.metadata else None
332-
logger.warning(
333-
"autofix.on_completion_hook.group_not_found",
334-
extra={
335-
"run_id": run_id,
336-
"organization_id": organization.id,
337-
"group_id": group_id,
338-
},
339-
)
340-
return
341-
342314
if current_step is None:
343315
logger.warning(
344316
"autofix.on_completion_hook.no_current_step",

0 commit comments

Comments
 (0)