Skip to content

Commit ca1be44

Browse files
author
Stephen Cefali
authored
fix(jira-server): try a second project for jira server if the first one fails (#56439)
When Sentry loads the initial config for Jira Server, we pick the first project we find if there isn't one set. Sometimes that project is in a bad state. So if the first request fails, we try the second project and use that instead.
1 parent bdbf5b3 commit ca1be44

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Diff for: src/sentry/integrations/jira_server/integration.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -705,17 +705,24 @@ def get_create_issue_config(self, group, user, **kwargs):
705705
project_id = params.get("project", defaults.get("project"))
706706
jira_projects = self.get_projects()
707707

708+
try_other_projects = False
708709
if not project_id:
709710
project_id = jira_projects[0]["id"]
711+
try_other_projects = True
710712

711713
client = self.get_client()
712714
try:
713715
issue_type_choices = client.get_issue_types(project_id)
714716
except ApiError:
715-
# re-fetch projects list w/o caching and try again
716-
jira_projects = self.get_projects(False)
717-
project_id = jira_projects[0]["id"]
718-
issue_type_choices = client.get_issue_types(project_id)
717+
if try_other_projects:
718+
# try again with a different project
719+
other_projects = list(filter(lambda x: x["id"] != str(project_id), jira_projects))
720+
if not other_projects:
721+
raise
722+
project_id = other_projects[0]["id"]
723+
issue_type_choices = client.get_issue_types(project_id)
724+
else:
725+
raise
719726

720727
issue_type_choices_formatted = [
721728
(choice["id"], choice["name"]) for choice in issue_type_choices["values"]

Diff for: tests/sentry/integrations/jira_server/test_integration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def test_get_create_issue_config_with_default(self):
411411
@responses.activate
412412
def test_get_create_issue_config_with_default_project_issue_types_erroring(self):
413413
"""Test that if you have a default project set that's returning an error when
414-
we try to get the issue types we re-fetch the projects list w/o caching and try again
414+
we try to get the issue types we try a second project
415415
"""
416416
event = self.store_event(
417417
data={"message": "oh no", "timestamp": self.min_ago}, project_id=self.project.id
@@ -421,7 +421,7 @@ def test_get_create_issue_config_with_default_project_issue_types_erroring(self)
421421
assert self.installation.org_integration is not None
422422
self.installation.org_integration = integration_service.update_organization_integration(
423423
org_integration_id=self.installation.org_integration.id,
424-
config={"project_issue_defaults": {str(group.project_id): {"project": "10000"}}},
424+
config={"project_issue_defaults": {str(group.project_id): {}}},
425425
)
426426
responses.add(
427427
responses.GET,

0 commit comments

Comments
 (0)