Skip to content

fix(owners) Fix failure when ownership rules have bad owners #13482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/sentry/models/projectownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ def get_autoassign_owner(cls, project_id, data):
score = candidate
owners = rule.owners
actors = filter(None, resolve_actors(owners, project_id).values())

# Can happen if the ownership rule references a user/team that no longer
# is assigned to the project or has been removed from the org.
if not actors:
return None
return actors[0].resolve()

@classmethod
Expand Down
29 changes: 28 additions & 1 deletion tests/sentry/tasks/post_process/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_owner_assignment_assign_user(self):
assert assignee.user == self.user
assert assignee.team is None

def test_owner_assignment_ownership_does_not_exist(self):
def test_owner_assignment_ownership_no_matching_owners(self):
event = self.store_event(
data={
'message': 'oh no',
Expand Down Expand Up @@ -241,6 +241,33 @@ def test_owner_assignment_existing_assignment(self):
assert assignee.user is None
assert assignee.team == self.team

def test_owner_assignment_owner_is_gone(self):
self.make_ownership()
# Remove the team so the rule match will fail to resolve
self.team.delete()

event = self.store_event(
data={
'message': 'oh no',
'platform': 'python',
'stacktrace': {
'frames': [
{'filename': 'src/app/example.py'}
]
}
},
project_id=self.project.id
)
post_process_group(
event=event,
is_new=False,
is_regression=False,
is_sample=False,
is_new_group_environment=False,
)
assignee = event.group.assignee_set.first()
assert assignee is None

@patch('sentry.tasks.servicehooks.process_service_hook')
def test_service_hook_fires_on_new_event(self, mock_process_service_hook):
group = self.create_group(project=self.project)
Expand Down