Skip to content

Commit e72df84

Browse files
authored
chore(explorer): Return both project slugs and ids (#102148)
Modify the RPC that gets all project IDs for an org to also get project slugs
1 parent f350ff0 commit e72df84

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/sentry/seer/endpoints/seer_rpc.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,17 @@ def get_organization_slug(*, org_id: int) -> dict:
242242

243243

244244
def get_organization_project_ids(*, org_id: int) -> dict:
245-
"""Get all project IDs for an organization"""
245+
"""Get all projects (IDs and slugs) for an organization"""
246246
from sentry.models.project import Project
247247

248248
try:
249249
organization = Organization.objects.get(id=org_id)
250250
except Organization.DoesNotExist:
251-
return {"project_ids": []}
251+
return {"projects": []}
252252

253-
project_ids = list(
254-
Project.objects.filter(organization=organization).values_list("id", flat=True)
255-
)
256-
return {"project_ids": project_ids}
253+
projects = list(Project.objects.filter(organization=organization).values("id", "slug"))
254+
255+
return {"projects": projects}
257256

258257

259258
def _can_use_prevent_ai_features(org: Organization) -> bool:

tests/sentry/seer/explorer/test_tools.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from sentry.models.group import Group
1111
from sentry.models.groupassignee import GroupAssignee
1212
from sentry.models.repository import Repository
13+
from sentry.seer.endpoints.seer_rpc import get_organization_project_ids
1314
from sentry.seer.explorer.tools import (
1415
execute_trace_query_chart,
1516
execute_trace_query_table,
@@ -371,17 +372,22 @@ def test_execute_trace_query_table_aggregates_mode_multiple_functions(self):
371372

372373
def test_get_organization_project_ids(self):
373374
"""Test the get_organization_project_ids RPC method"""
374-
from sentry.seer.endpoints.seer_rpc import get_organization_project_ids
375-
376375
# Test with valid organization
377376
result = get_organization_project_ids(org_id=self.organization.id)
378-
assert "project_ids" in result
379-
assert isinstance(result["project_ids"], list)
380-
assert self.project.id in result["project_ids"]
377+
assert "projects" in result
378+
assert isinstance(result["projects"], list)
379+
assert len(result["projects"]) > 0
380+
# Check that projects have both id and slug
381+
project = result["projects"][0]
382+
assert "id" in project
383+
assert "slug" in project
384+
# Check that our project is in the results
385+
project_ids = [p["id"] for p in result["projects"]]
386+
assert self.project.id in project_ids
381387

382388
# Test with nonexistent organization
383389
result = get_organization_project_ids(org_id=99999)
384-
assert result == {"project_ids": []}
390+
assert result == {"projects": []}
385391

386392

387393
class TestGetTraceWaterfall(APITransactionTestCase, SpanTestCase, SnubaTestCase):

0 commit comments

Comments
 (0)