Skip to content

Commit 5ad8658

Browse files
authored
fix(owners) Fix failure when ownership rules have bad owners (#13482)
Ownership rules have no relational links to actual users in an organization. This means they can reference teams/users that are no longer are assigned to the project or no longer exist in the organization. Fixes SENTRY-AXY
1 parent 92c1945 commit 5ad8658

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/sentry/models/projectownership.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ def get_autoassign_owner(cls, project_id, data):
8787
score = candidate
8888
owners = rule.owners
8989
actors = filter(None, resolve_actors(owners, project_id).values())
90+
91+
# Can happen if the ownership rule references a user/team that no longer
92+
# is assigned to the project or has been removed from the org.
93+
if not actors:
94+
return None
9095
return actors[0].resolve()
9196

9297
@classmethod

tests/sentry/tasks/post_process/tests.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def test_owner_assignment_assign_user(self):
191191
assert assignee.user == self.user
192192
assert assignee.team is None
193193

194-
def test_owner_assignment_ownership_does_not_exist(self):
194+
def test_owner_assignment_ownership_no_matching_owners(self):
195195
event = self.store_event(
196196
data={
197197
'message': 'oh no',
@@ -241,6 +241,33 @@ def test_owner_assignment_existing_assignment(self):
241241
assert assignee.user is None
242242
assert assignee.team == self.team
243243

244+
def test_owner_assignment_owner_is_gone(self):
245+
self.make_ownership()
246+
# Remove the team so the rule match will fail to resolve
247+
self.team.delete()
248+
249+
event = self.store_event(
250+
data={
251+
'message': 'oh no',
252+
'platform': 'python',
253+
'stacktrace': {
254+
'frames': [
255+
{'filename': 'src/app/example.py'}
256+
]
257+
}
258+
},
259+
project_id=self.project.id
260+
)
261+
post_process_group(
262+
event=event,
263+
is_new=False,
264+
is_regression=False,
265+
is_sample=False,
266+
is_new_group_environment=False,
267+
)
268+
assignee = event.group.assignee_set.first()
269+
assert assignee is None
270+
244271
@patch('sentry.tasks.servicehooks.process_service_hook')
245272
def test_service_hook_fires_on_new_event(self, mock_process_service_hook):
246273
group = self.create_group(project=self.project)

0 commit comments

Comments
 (0)