Skip to content

Conversation

ceorourke
Copy link
Member

@ceorourke ceorourke commented Sep 15, 2025

Now that we are no longer calling get_open_periods_for_group in the GroupDetailsEndpoint (#99519) we can clean up the code that constructs an open period when there isn't actually a GroupOpenPeriod (this code was used before we ran the backfill) to return the objects and serialize them normally. This PR also adds the id to the response. A near future PR will add a serializer for GroupOpenPeriodActivity and add that to the response as well.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Sep 15, 2025
Copy link

codecov bot commented Sep 15, 2025

✅ All tests passed in 19559.72s



@dataclass
class OpenPeriod:
Copy link
Member Author

Choose a reason for hiding this comment

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

This is replaced by GroupOpenPeriodResponse in the serializer

group: Group,
query_start: datetime | None = None,
query_end: datetime | None = None,
offset: int | 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.

I removed offset because I'm not longer using the GenericOffsetPaginator and the way it was used here (by doing a greater than on the id field) seemed like a security risk - if you passed a random offset you could access various open period results

@ceorourke ceorourke marked this pull request as ready for review September 16, 2025 16:59
@ceorourke ceorourke requested a review from a team as a code owner September 16, 2025 16:59
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.


if offset and limit:
return open_periods[offset : offset + limit]
if not query_start:
Copy link
Contributor

Choose a reason for hiding this comment

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

👀 well, this is a lot simpler now.

group_open_periods = group_open_periods.filter(date_ended__lte=query_end)

return open_periods
return group_open_periods[:limit]
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL that django is smart and will add this to db query as the limit rather than getting all the data and filtering the results in memory. 🎉

@@ -1,7 +1,5 @@
import logging
Copy link
Contributor

Choose a reason for hiding this comment

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

unrelated to the changes in this file -- but thoughts on moving this model into src/sentry/issues/models since it's an issue platform model?

if not target_group:
return Response(
{"detail": "Group not found. Could not query open periods."},
status=status.HTTP_200_OK,
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be a 404 (or another 4XX status) response since the group isn't found?

Copy link
Member Author

Choose a reason for hiding this comment

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

You know that's what I thought too, but I based this off of https://github.com/getsentry/sentry/blob/master/src/sentry/workflow_engine/endpoints/organization_detector_index.py#L422-L426 I think, happy to change it though

}


class GroupOpenPeriodResponse(TypedDict):
Copy link
Contributor

Choose a reason for hiding this comment

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

nice! 🎉 i feel like i should add these for all the workflow engine serializers.

group=target_group,
query_start=start,
query_end=end,
limit=limit,
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: Pagination Parameter Validation and Usage Issues

The per_page query parameter's validation is incomplete: non-numeric input or non-positive values can lead to unhandled exceptions (500s), and assert is unreliable for validation in production. Additionally, per_page is incorrectly used to pre-limit results before OffsetPaginator, causing double-limiting and incorrect pagination behavior.

Fix in Cursor Fix in Web

@ceorourke ceorourke merged commit 2bc4d63 into master Sep 17, 2025
63 checks passed
@ceorourke ceorourke deleted the ceorourke/return-groupopenperiod-object branch September 17, 2025 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants