-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(Jira-Server): Adds halts, better exceptions for failed syncs #95281
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
GabeVillalobos
merged 4 commits into
master
from
gv/fix-jira-sync-failure-categorization
Jul 15, 2025
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7389d2a
fix(Jira-Server): Adds halts, better exceptions for failed syncs
GabeVillalobos 8765f77
Updates Jira/VSTS to use new exception types.
GabeVillalobos bcd2a13
Adds new tests, fixes broken ones
GabeVillalobos 9e00c3d
Fixes jira_server tests
GabeVillalobos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,12 @@ | |
|
|
||
| from sentry.integrations.errors import OrganizationIntegrationNotFound | ||
| from sentry.integrations.example import ExampleIntegration | ||
| from sentry.integrations.mixins.issues import IntegrationSyncTargetNotFound | ||
| from sentry.integrations.models import ExternalIssue, Integration | ||
| from sentry.integrations.models.organization_integration import OrganizationIntegration | ||
| from sentry.integrations.tasks import sync_assignee_outbound | ||
| from sentry.integrations.types import EventLifecycleOutcome | ||
| from sentry.shared_integrations.exceptions import IntegrationInstallationConfigurationError | ||
| from sentry.testutils.asserts import assert_halt_metric, assert_success_metric | ||
| from sentry.testutils.cases import TestCase | ||
| from sentry.testutils.silo import assume_test_silo_mode_of | ||
|
|
@@ -35,19 +37,23 @@ def setUp(self): | |
| }, | ||
| ) | ||
|
|
||
| @mock.patch("sentry.integrations.utils.metrics.EventLifecycle.record_event") | ||
| @mock.patch.object(ExampleIntegration, "sync_assignee_outbound") | ||
| def test_syncs_outbound_assignee(self, mock_sync_assignee, mock_record_event): | ||
| external_issue = self.create_integration_external_issue( | ||
| # Create a shared external issue for most tests | ||
| self.external_issue = self.create_integration_external_issue( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was repeated in nearly every single test, so I hoisted it into the setup instead. |
||
| group=self.group, | ||
| key="foo-1234", | ||
| integration=self.example_integration, | ||
| ) | ||
|
|
||
| sync_assignee_outbound(external_issue.id, self.user.id, True, None) | ||
| # Verify the external issue was created successfully | ||
| assert ExternalIssue.objects.filter(id=self.external_issue.id).exists() | ||
|
|
||
| @mock.patch("sentry.integrations.utils.metrics.EventLifecycle.record_event") | ||
| @mock.patch.object(ExampleIntegration, "sync_assignee_outbound") | ||
| def test_syncs_outbound_assignee(self, mock_sync_assignee, mock_record_event): | ||
| sync_assignee_outbound(self.external_issue.id, self.user.id, True, None) | ||
| mock_sync_assignee.assert_called_once() | ||
| mock_sync_assignee.assert_called_with( | ||
| external_issue, mock.ANY, assign=True, assignment_source=None | ||
| self.external_issue, mock.ANY, assign=True, assignment_source=None | ||
| ) | ||
|
|
||
| user_arg = mock_sync_assignee.call_args_list[0][0][1] | ||
|
|
@@ -61,14 +67,8 @@ def test_syncs_outbound_assignee(self, mock_sync_assignee, mock_record_event): | |
| def test_sync_failure(self, mock_sync_assignee, mock_record_failure): | ||
| mock_sync_assignee.side_effect = raise_sync_assignee_exception | ||
|
|
||
| external_issue = self.create_integration_external_issue( | ||
| group=self.group, | ||
| key="foo-1234", | ||
| integration=self.example_integration, | ||
| ) | ||
|
|
||
| with pytest.raises(Exception) as exc: | ||
| sync_assignee_outbound(external_issue.id, self.user.id, True, None) | ||
| sync_assignee_outbound(self.external_issue.id, self.user.id, True, None) | ||
|
|
||
| assert exc.match("Something went wrong") | ||
| mock_record_failure.assert_called_once() | ||
|
|
@@ -86,13 +86,8 @@ def test_skips_syncing_if_should_sync_false( | |
| self, mock_should_sync, mock_sync_assignee, mock_record_event | ||
| ): | ||
| mock_should_sync.return_value = False | ||
| external_issue = self.create_integration_external_issue( | ||
| group=self.group, | ||
| key="foo-1234", | ||
| integration=self.example_integration, | ||
| ) | ||
|
|
||
| sync_assignee_outbound(external_issue.id, self.user.id, True, None) | ||
| sync_assignee_outbound(self.external_issue.id, self.user.id, True, None) | ||
| mock_sync_assignee.assert_not_called() | ||
|
|
||
| assert mock_record_event.call_count == 2 | ||
|
|
@@ -120,38 +115,55 @@ def test_missing_issue_sync(self, mock_sync_assignee, mock_record_event): | |
|
|
||
| @mock.patch.object(ExampleIntegration, "sync_assignee_outbound") | ||
| def test_missing_integration_installation(self, mock_sync_assignee): | ||
| external_issue = self.create_integration_external_issue( | ||
| group=self.group, | ||
| key="foo-1234", | ||
| integration=self.example_integration, | ||
| ) | ||
|
|
||
| # Delete all integrations, but ensure we still have an external issue | ||
| with assume_test_silo_mode_of(Integration): | ||
| Integration.objects.filter().delete() | ||
|
|
||
| assert ExternalIssue.objects.filter(id=external_issue.id).exists() | ||
| sync_assignee_outbound(external_issue.id, self.user.id, True, None) | ||
| sync_assignee_outbound(self.external_issue.id, self.user.id, True, None) | ||
| mock_sync_assignee.assert_not_called() | ||
|
|
||
| @mock.patch("sentry.integrations.utils.metrics.EventLifecycle.record_event") | ||
| @mock.patch.object(ExampleIntegration, "sync_assignee_outbound") | ||
| def test_missing_organization_integration(self, mock_sync_assignee, mock_record_event): | ||
| external_issue = self.create_integration_external_issue( | ||
| group=self.group, | ||
| key="foo-1234", | ||
| integration=self.example_integration, | ||
| ) | ||
|
|
||
| # Delete all organization integrations, but ensure we still have an external issue | ||
| with assume_test_silo_mode_of(OrganizationIntegration): | ||
| OrganizationIntegration.objects.filter().delete() | ||
|
|
||
| assert ExternalIssue.objects.filter(id=external_issue.id).exists() | ||
| sync_assignee_outbound(external_issue.id, self.user.id, True, None) | ||
| sync_assignee_outbound(self.external_issue.id, self.user.id, True, None) | ||
| mock_sync_assignee.assert_not_called() | ||
|
|
||
| assert mock_record_event.call_count == 2 | ||
| assert_halt_metric( | ||
| mock_record_event, OrganizationIntegrationNotFound("missing org_integration") | ||
| ) | ||
|
|
||
| @mock.patch("sentry.integrations.utils.metrics.EventLifecycle.record_event") | ||
| @mock.patch.object(ExampleIntegration, "sync_assignee_outbound") | ||
| def test_integration_sync_target_not_found(self, mock_sync_assignee, mock_record_event): | ||
| mock_sync_assignee.side_effect = IntegrationSyncTargetNotFound("No matching user found") | ||
|
|
||
| sync_assignee_outbound(self.external_issue.id, self.user.id, True, None) | ||
| mock_sync_assignee.assert_called_once() | ||
|
|
||
| assert mock_record_event.call_count == 2 | ||
| assert_halt_metric( | ||
| mock_record_event, IntegrationSyncTargetNotFound("No matching user found") | ||
| ) | ||
|
|
||
| @mock.patch("sentry.integrations.utils.metrics.EventLifecycle.record_event") | ||
| @mock.patch.object(ExampleIntegration, "sync_assignee_outbound") | ||
| def test_integration_installation_configuration_error( | ||
| self, mock_sync_assignee, mock_record_event | ||
| ): | ||
| mock_sync_assignee.side_effect = IntegrationInstallationConfigurationError( | ||
| "Insufficient permissions to assign user" | ||
| ) | ||
|
|
||
| sync_assignee_outbound(self.external_issue.id, self.user.id, True, None) | ||
| mock_sync_assignee.assert_called_once() | ||
|
|
||
| assert mock_record_event.call_count == 2 | ||
| assert_halt_metric( | ||
| mock_record_event, | ||
| IntegrationInstallationConfigurationError("Insufficient permissions to assign user"), | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leaving it as a vestigial reminder to do this in the future 😅 We do want this eventually.