@@ -40,7 +40,7 @@ class Meta:
40
40
]
41
41
42
42
@classmethod
43
- def create_from_occurrence (cls , occurrence , group , open_period ):
43
+ def create_from_occurrence (self , occurrence , group , open_period ):
44
44
"""
45
45
Creates an IncidentGroupOpenPeriod relationship from an issue occurrence.
46
46
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):
84
84
85
85
if incident :
86
86
# Incident exists, create the relationship immediately
87
- return cls .create_relationship (incident , open_period )
87
+ return self .create_relationship (incident , open_period )
88
88
else :
89
89
# Incident doesn't exist yet, create a placeholder relationship
90
90
# 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 )
92
92
93
93
except Exception as e :
94
94
logger .exception (
@@ -102,32 +102,23 @@ def create_from_occurrence(cls, occurrence, group, open_period):
102
102
return None
103
103
104
104
@classmethod
105
- def create_relationship (cls , incident , open_period ):
105
+ def create_relationship (self , incident , open_period ):
106
106
"""
107
- Creates or updates an IncidentGroupOpenPeriod relationship.
107
+ Creates IncidentGroupOpenPeriod relationship.
108
108
109
109
Args:
110
110
incident: The Incident to link
111
111
open_period: The GroupOpenPeriod to link
112
112
"""
113
113
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 (
116
115
group_open_period = open_period ,
117
116
defaults = {
118
117
"incident_id" : incident .id ,
119
118
"incident_identifier" : incident .identifier ,
120
119
},
121
120
)
122
121
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
-
131
122
return incident_group_open_period
132
123
133
124
except Exception as e :
@@ -142,7 +133,7 @@ def create_relationship(cls, incident, open_period):
142
133
return None
143
134
144
135
@classmethod
145
- def create_placeholder_relationship (cls , alert_id , open_period , project ):
136
+ def create_placeholder_relationship (self , alert_id , open_period , project ):
146
137
"""
147
138
Creates a placeholder relationship when the incident doesn't exist yet.
148
139
This will be updated when the incident is created.
@@ -172,7 +163,7 @@ def create_placeholder_relationship(cls, alert_id, open_period, project):
172
163
return None
173
164
174
165
@classmethod
175
- def create_pending_relationships_for_incident (cls , incident , alert_rule ):
166
+ def create_pending_relationships_for_incident (self , incident , alert_rule ):
176
167
"""
177
168
Creates IncidentGroupOpenPeriod relationships for any groups that were created
178
169
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):
191
182
192
183
for open_period in pending_open_periods :
193
184
# Create the relationship
194
- relationship = cls .create_relationship (incident , open_period )
185
+ relationship = self .create_relationship (incident , open_period )
195
186
if relationship :
196
187
# Remove the pending flag from the open_period data
197
188
data = open_period .data or {}
0 commit comments