Skip to content
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
6 changes: 2 additions & 4 deletions src/sentry/integrations/utils/stacktrace_link.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -82,9 +82,7 @@ class StacktraceLinkOutcome(TypedDict):


def get_stacktrace_config(
configs: list[RepositoryProjectPathConfig],
ctx: StacktraceLinkContext,
organization: Organization | None = None,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The organization is not used within the function.

configs: Sequence[RepositoryProjectPathConfig], ctx: StacktraceLinkContext
) -> StacktraceLinkOutcome:
result: StacktraceLinkOutcome = {
"source_url": None,
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/issues/endpoints/project_stacktrace_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 9 additions & 17 deletions tests/sentry/issues/endpoints/test_project_stacktrace_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will let each test decide what code mappings makes sense to create rather than create it for each test.


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"""
Expand Down Expand Up @@ -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)]
Expand All @@ -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"}
)
Expand All @@ -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)]

Expand All @@ -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,
Expand Down
Loading