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
7 changes: 6 additions & 1 deletion src/sentry/rules/history/endpoints/project_rule_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any, TypedDict

from drf_spectacular.utils import extend_schema
from rest_framework.exceptions import ParseError
from rest_framework.request import Request
from rest_framework.response import Response

Expand All @@ -15,6 +16,7 @@
from sentry.api.utils import get_date_range_from_params
from sentry.apidocs.constants import RESPONSE_FORBIDDEN, RESPONSE_NOT_FOUND, RESPONSE_UNAUTHORIZED
from sentry.apidocs.parameters import GlobalParams, IssueAlertParams
from sentry.exceptions import InvalidParams
from sentry.models.project import Project
from sentry.models.rule import Rule
from sentry.rules.history import fetch_rule_hourly_stats
Expand Down Expand Up @@ -65,6 +67,9 @@
"""
Note that results are returned in hourly buckets.
"""
start, end = get_date_range_from_params(request.GET)
try:
start, end = get_date_range_from_params(request.GET)
except InvalidParams as e:
raise ParseError(detail=str(e))

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.
Comment thread
kcons marked this conversation as resolved.
Dismissed
results = fetch_rule_hourly_stats(rule, start, end)
return Response(serialize(results, request.user, TimeSeriesValueSerializer()))
11 changes: 11 additions & 0 deletions tests/sentry/rules/history/endpoints/test_project_rule_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,14 @@ def test(self) -> None:
{"date": now - timedelta(hours=1), "count": 1},
{"date": now, "count": 0},
]

def test_invalid_date_range(self) -> None:
rule = self.create_project_rule(project=self.event.project)
self.login_as(self.user)
self.get_error_response(
self.organization.slug,
self.project.slug,
rule.id,
start="invalid",
status_code=400,
)
Loading