diff --git a/src/sentry/integrations/utils/stacktrace_link.py b/src/sentry/integrations/utils/stacktrace_link.py index 98c3ed935a05ad..b31d3e0870dd42 100644 --- a/src/sentry/integrations/utils/stacktrace_link.py +++ b/src/sentry/integrations/utils/stacktrace_link.py @@ -1,6 +1,7 @@ from __future__ import annotations import logging +from collections.abc import Sequence from typing import TYPE_CHECKING, NotRequired, TypedDict from sentry.constants import ObjectStatus @@ -10,7 +11,6 @@ from sentry.issues.auto_source_code_config.code_mapping import ( convert_stacktrace_frame_path_to_source_path, ) -from sentry.models.organization import Organization from sentry.models.repository import Repository from sentry.shared_integrations.exceptions import ApiError from sentry.utils.event_frames import EventFrame @@ -82,9 +82,7 @@ class StacktraceLinkOutcome(TypedDict): def get_stacktrace_config( - configs: list[RepositoryProjectPathConfig], - ctx: StacktraceLinkContext, - organization: Organization | None = None, + configs: Sequence[RepositoryProjectPathConfig], ctx: StacktraceLinkContext ) -> StacktraceLinkOutcome: result: StacktraceLinkOutcome = { "source_url": None, diff --git a/src/sentry/issues/endpoints/project_stacktrace_link.py b/src/sentry/issues/endpoints/project_stacktrace_link.py index be194b8b1fd285..5d4dae85abc107 100644 --- a/src/sentry/issues/endpoints/project_stacktrace_link.py +++ b/src/sentry/issues/endpoints/project_stacktrace_link.py @@ -154,7 +154,7 @@ def get(self, request: Request, project: Project) -> Response: scope = Scope.get_isolation_scope() set_top_tags(scope, project, ctx, len(configs) > 0) - result = get_stacktrace_config(configs, ctx, project.organization) + result = get_stacktrace_config(configs, ctx) error = result["error"] src_path = result["src_path"] # Post-processing before exiting scope context diff --git a/tests/sentry/issues/endpoints/test_project_stacktrace_link.py b/tests/sentry/issues/endpoints/test_project_stacktrace_link.py index 5a9acdc89631ed..3180c6c25d28af 100644 --- a/tests/sentry/issues/endpoints/test_project_stacktrace_link.py +++ b/tests/sentry/issues/endpoints/test_project_stacktrace_link.py @@ -124,21 +124,7 @@ def expected_configurations( class ProjectStacktraceLinkTest(BaseProjectStacktraceLink): - endpoint = "sentry-api-0-project-stacktrace-link" - - def setUp(self) -> None: - BaseProjectStacktraceLink.setUp(self) - self.code_mapping1 = self._create_code_mapping( - stack_root="usr/src/getsentry/", - source_root="", - ) - self.code_mapping2 = self._create_code_mapping( - stack_root="sentry/", - source_root="src/sentry/", - automatically_generated=True, # Created by the automation - ) - - self.filepath = "usr/src/getsentry/src/sentry/src/sentry/utils/safe.py" + filepath = "usr/src/getsentry/src/sentry/src/sentry/utils/safe.py" def test_no_filepath(self) -> None: """The file query search is missing""" @@ -168,10 +154,11 @@ def test_no_configs(self) -> None: def test_file_not_found_error(self) -> None: """File matches code mapping but it cannot be found in the source repository.""" + cm = self._create_code_mapping(stack_root="usr/src/getsentry/", source_root="") response = self.get_success_response( self.organization.slug, self.project.slug, qs_params={"file": self.filepath} ) - assert response.data["config"] == self.expected_configurations(self.code_mapping1) + assert response.data["config"] == self.expected_configurations(cm) assert not response.data["sourceUrl"] assert response.data["error"] == "file_not_found" assert response.data["integrations"] == [serialized_integration(self.integration)] @@ -182,6 +169,8 @@ def test_file_not_found_error(self) -> None: def test_stack_root_mismatch_error(self) -> None: """Looking for a stacktrace file path that will not match any code mappings""" + # At least one code mapping to produce the stack_root_mismatch error + self._create_code_mapping(stack_root="usr/src/getsentry/", source_root="") response = self.get_success_response( self.organization.slug, self.project.slug, qs_params={"file": "wrong/file/path"} ) @@ -195,10 +184,11 @@ def test_config_and_source_url(self) -> None: with patch.object( ExampleIntegration, "get_stacktrace_link", return_value="https://sourceurl.com/" ): + cm = self._create_code_mapping(stack_root="usr/src/getsentry/", source_root="") response = self.get_success_response( self.organization.slug, self.project.slug, qs_params={"file": self.filepath} ) - assert response.data["config"] == self.expected_configurations(self.code_mapping1) + assert response.data["config"] == self.expected_configurations(cm) assert response.data["sourceUrl"] == "https://sourceurl.com/" assert response.data["integrations"] == [serialized_integration(self.integration)] @@ -207,6 +197,8 @@ def test_file_no_stack_root_match(self, mock_integration: MagicMock) -> None: # Pretend that the file was not found in the repository mock_integration.return_value = None + # At least one code mapping to produce the stack_root_mismatch error + self._create_code_mapping(stack_root="usr/src/getsentry/", source_root="") response = self.get_success_response( self.organization.slug, self.project.slug,