Repository navigation
ref(typing): Let shared helpers take a service account #129413
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ | |
| from datetime import datetime | ||
| from typing import Any, Literal | ||
|
|
||
| from django.contrib.auth.models import AnonymousUser | ||
| from django.db.models import Q, QuerySet | ||
| from django.utils import timezone as django_timezone | ||
| from django.utils.timezone import now | ||
|
|
@@ -17,6 +16,7 @@ | |
| from urllib3 import BaseHTTPResponse | ||
|
|
||
| from sentry import features, options | ||
| from sentry.auth.principal import RequestPrincipal, acting_user_id | ||
| from sentry.constants import ENABLE_SEER_CODING_DEFAULT, ObjectStatus | ||
| from sentry.identity import default_manager as identity_manager | ||
| from sentry.identity.mcp import McpIdentityProvider | ||
|
|
@@ -66,8 +66,6 @@ | |
| from sentry.seer.signed_seer_api import SeerViewerContext | ||
| from sentry.tasks.seer.context_engine_index import build_service_map, index_org_project_knowledge | ||
| from sentry.tasks.seer.explorer_index import dispatch_explorer_index_projects | ||
| from sentry.users.models.user import User | ||
| from sentry.users.services.user import RpcUser | ||
| from sentry.utils.prompts import ( | ||
| get_prompt_activities_for_user, | ||
| seer_monitoring_provider_dont_ask_feature, | ||
|
|
@@ -315,7 +313,7 @@ def execute(cls, organization: Organization, run_id: int) -> None: | |
| def __init__( | ||
| self, | ||
| organization: Organization, | ||
| user: User | RpcUser | AnonymousUser | None = None, | ||
| user: RequestPrincipal | None = None, | ||
| project: Project | None = None, | ||
| group: Group | None = None, | ||
| category_key: str | None = None, | ||
|
|
@@ -339,6 +337,7 @@ def __init__( | |
| ): | ||
| self.organization = organization | ||
| self.user = user | ||
| self._user_id = acting_user_id(user) if user is not None else None | ||
| self.project = project | ||
| self.group = group | ||
| self.custom_tools = custom_tools or [] | ||
|
|
@@ -391,8 +390,8 @@ def __init__( | |
|
|
||
| def _build_viewer_context(self) -> SeerViewerContext: | ||
| context = SeerViewerContext(organization_id=self.organization.id) | ||
| if self.user and hasattr(self.user, "id") and self.user.id is not None: | ||
| context["user_id"] = self.user.id | ||
| if self._user_id is not None: | ||
| context["user_id"] = self._user_id | ||
| return context | ||
|
|
||
| def start_run( | ||
|
|
@@ -515,11 +514,7 @@ def start_run( | |
| ) | ||
| ) | ||
|
|
||
| user_id = ( | ||
| self.user.id | ||
| if self.user and hasattr(self.user, "id") and self.user.id is not None | ||
| else None | ||
| ) | ||
| user_id = self._user_id | ||
|
|
||
| def _create_agent_run(run: SeerRun) -> None: | ||
| if record_in_history: | ||
|
|
@@ -587,11 +582,7 @@ def start_feature_run( | |
| Explicit agent_run_options override any options derived from organization | ||
| configuration. | ||
| """ | ||
| user_id = ( | ||
| self.user.id | ||
| if self.user and hasattr(self.user, "id") and self.user.id is not None | ||
| else None | ||
| ) | ||
| user_id = self._user_id | ||
|
|
||
| def _create_agent_run(run: SeerRun) -> None: | ||
| SeerAgentRun.objects.create( | ||
|
|
@@ -830,11 +821,7 @@ def continue_run( | |
| if ui_tools: | ||
| chat_body["ui_tools"] = ui_tools | ||
|
|
||
| monitoring_user_id = ( | ||
| self.user.id | ||
| if self.user and not isinstance(self.user, AnonymousUser) and self.user.id is not None | ||
| else None | ||
| ) | ||
| monitoring_user_id = self._user_id | ||
| monitoring_provider_connections = get_monitoring_provider_connections( | ||
| self.organization, monitoring_user_id | ||
| ) | ||
|
|
@@ -932,7 +919,7 @@ def get_runs( | |
| start: datetime | None = None, | ||
| end: datetime | None = None, | ||
| ) -> QuerySet[SeerRun]: | ||
| user_id = int(self.user.id) if self.user is not None and self.user.id is not None else None | ||
| user_id = self._user_id | ||
| queryset = queryset_for_query(query, self.organization, user_id) | ||
| queryset = queryset.filter( | ||
| Q(agent__project_id__isnull=True) | Q(agent__project_id__in=accessible_project_ids) | ||
|
|
@@ -954,13 +941,8 @@ def latest_run( | |
| run__organization_id=self.organization.id, | ||
| source=self.category_key or "", | ||
| ) | ||
| if ( | ||
| only_current_user | ||
| and self.user | ||
| and hasattr(self.user, "id") | ||
| and self.user.id is not None | ||
| ): | ||
| qs = qs.filter(run__user_id=int(self.user.id)) | ||
| if only_current_user and self._user_id is not None: | ||
| qs = qs.filter(run__user_id=self._user_id) | ||
|
Contributor
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. Latest run skips user scopingMedium Severity
Reviewed by Cursor Bugbot for commit 246b3c3. Configure here. |
||
| if group_id is not None: | ||
| qs = qs.filter(group_id=group_id) | ||
| elif self.category_value is not None: | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.