Skip to content

Commit dcd5c36

Browse files
snigdhasceorourke
authored andcommitted
Address code review comments
1 parent d414c4a commit dcd5c36

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

src/sentry/issues/ingest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ def save_issue_occurrence(
7979
IncidentGroupOpenPeriod.create_from_occurrence(
8080
occurrence, group_info.group, open_period
8181
)
82+
else:
83+
logger.error(
84+
"save_issue_occurrence.no_open_period",
85+
extra={
86+
"group_id": group_info.group.id,
87+
"occurrence_id": occurrence.id,
88+
},
89+
)
8290

8391
send_issue_occurrence_to_eventstream(event, occurrence, group_info)
8492
return occurrence, group_info

src/sentry/workflow_engine/models/incident_groupopenperiod.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Meta:
4040
]
4141

4242
@classmethod
43-
def create_from_occurrence(cls, occurrence, group, open_period):
43+
def create_from_occurrence(self, occurrence, group, open_period):
4444
"""
4545
Creates an IncidentGroupOpenPeriod relationship from an issue occurrence.
4646
This method handles the case where the incident might not exist yet.
@@ -84,11 +84,11 @@ def create_from_occurrence(cls, occurrence, group, open_period):
8484

8585
if incident:
8686
# Incident exists, create the relationship immediately
87-
return cls.create_relationship(incident, open_period)
87+
return self.create_relationship(incident, open_period)
8888
else:
8989
# Incident doesn't exist yet, create a placeholder relationship
9090
# that will be updated when the incident is created
91-
return cls.create_placeholder_relationship(alert_id, open_period, group.project)
91+
return self.create_placeholder_relationship(alert_id, open_period, group.project)
9292

9393
except Exception as e:
9494
logger.exception(
@@ -102,32 +102,23 @@ def create_from_occurrence(cls, occurrence, group, open_period):
102102
return None
103103

104104
@classmethod
105-
def create_relationship(cls, incident, open_period):
105+
def create_relationship(self, incident, open_period):
106106
"""
107-
Creates or updates an IncidentGroupOpenPeriod relationship.
107+
Creates IncidentGroupOpenPeriod relationship.
108108
109109
Args:
110110
incident: The Incident to link
111111
open_period: The GroupOpenPeriod to link
112112
"""
113113
try:
114-
# Create the relationship (or get existing one)
115-
incident_group_open_period, created = cls.objects.get_or_create(
114+
incident_group_open_period, _ = self.objects.get_or_create(
116115
group_open_period=open_period,
117116
defaults={
118117
"incident_id": incident.id,
119118
"incident_identifier": incident.identifier,
120119
},
121120
)
122121

123-
# Update incident_id if it changed (e.g., if a new incident was created)
124-
if not created and incident_group_open_period.incident_id != incident.id:
125-
incident_group_open_period.incident_id = incident.id
126-
incident_group_open_period.incident_identifier = incident.identifier
127-
incident_group_open_period.save(
128-
update_fields=["incident_id", "incident_identifier"]
129-
)
130-
131122
return incident_group_open_period
132123

133124
except Exception as e:
@@ -142,7 +133,7 @@ def create_relationship(cls, incident, open_period):
142133
return None
143134

144135
@classmethod
145-
def create_placeholder_relationship(cls, alert_id, open_period, project):
136+
def create_placeholder_relationship(self, alert_id, open_period, project):
146137
"""
147138
Creates a placeholder relationship when the incident doesn't exist yet.
148139
This will be updated when the incident is created.
@@ -172,7 +163,7 @@ def create_placeholder_relationship(cls, alert_id, open_period, project):
172163
return None
173164

174165
@classmethod
175-
def create_pending_relationships_for_incident(cls, incident, alert_rule):
166+
def create_pending_relationships_for_incident(self, incident, alert_rule):
176167
"""
177168
Creates IncidentGroupOpenPeriod relationships for any groups that were created
178169
before the incident. This handles the timing issue where groups might be created
@@ -191,7 +182,7 @@ def create_pending_relationships_for_incident(cls, incident, alert_rule):
191182

192183
for open_period in pending_open_periods:
193184
# Create the relationship
194-
relationship = cls.create_relationship(incident, open_period)
185+
relationship = self.create_relationship(incident, open_period)
195186
if relationship:
196187
# Remove the pending flag from the open_period data
197188
data = open_period.data or {}

0 commit comments

Comments
 (0)