Skip to content

Commit 5d6a254

Browse files
authored
fix(api) Don't fail on invalid queries to organization_teams endpoint (#51042)
Fixes SENTRY-ZCY
1 parent 937816f commit 5d6a254

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/sentry/api/endpoints/organization_teams.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.utils.translation import ugettext_lazy as _
66
from drf_spectacular.utils import OpenApiResponse, extend_schema
77
from rest_framework import serializers, status
8+
from rest_framework.exceptions import ParseError
89
from rest_framework.request import Request
910
from rest_framework.response import Response
1011

@@ -132,6 +133,10 @@ def get(self, request: Request, organization) -> Response:
132133
elif key == "slug":
133134
queryset = queryset.filter(slug__in=value)
134135
elif key == "id":
136+
try:
137+
value = [int(item) for item in value]
138+
except ValueError:
139+
raise ParseError(detail="Invalid id value")
135140
queryset = queryset.filter(id__in=value)
136141
else:
137142
queryset = queryset.none()

tests/sentry/api/endpoints/test_organization_teams.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ def test_query_by_id(self):
133133
team2 = self.create_team(organization=self.organization, name="bar")
134134
self.login_as(user=self.user)
135135

136+
path = f"/api/0/organizations/{self.organization.slug}/teams/?query=id:undefined"
137+
response = self.client.get(path)
138+
assert response.status_code == 400, response.content
139+
136140
path = f"/api/0/organizations/{self.organization.slug}/teams/?query=id:{team1.id}"
137141
response = self.client.get(path)
138142
assert response.status_code == 200, response.content

0 commit comments

Comments
 (0)