Skip to content

feat(discover): add endpoint for single saved query updates - #123926

Merged
lzhao-sentry merged 3 commits into
masterfrom
lzhao/feat/discover-saved-query-endpoint
Sep 9, 2026
Merged

feat(discover): add endpoint for single saved query updates#123926
lzhao-sentry merged 3 commits into
masterfrom
lzhao/feat/discover-saved-query-endpoint

Conversation

@lzhao-sentry

Copy link
Copy Markdown
Member

Changes

Address part of EXP-1166 in effort to port the remaining discover queries to explore all queries. This PR adds:

  • Discover starred endpoint to update starred status. API is not public yet

@linear-code

linear-code Bot commented Sep 9, 2026

Copy link
Copy Markdown

EXP-1166

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Sep 9, 2026
@lzhao-sentry
lzhao-sentry marked this pull request as ready for review September 9, 2026 18:04
@lzhao-sentry
lzhao-sentry requested a review from a team as a code owner September 9, 2026 18:04
Comment thread src/sentry/discover/endpoints/discover_saved_query_starred.py

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit aa721e2. Configure here.

Comment thread src/sentry/discover/endpoints/discover_saved_query_starred.py

@nikkikapadia nikkikapadia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm just some comments on cursor's comments

Comment thread src/sentry/discover/endpoints/discover_saved_query_starred.py
Comment thread src/sentry/discover/endpoints/discover_saved_query_starred.py
Comment on lines +66 to +70
try:
query = DiscoverSavedQuery.objects.get(
Q(is_homepage=False) | Q(is_homepage__isnull=True), id=id, organization=organization
)
except DiscoverSavedQuery.DoesNotExist:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The position field is accepted by the StarQuerySerializer but is silently ignored by the endpoint, which always appends the starred query to the end.
Severity: MEDIUM

Suggested Fix

Modify the endpoint to read the position value from the validated serializer data. Update DiscoverSavedQueryStarredManager.insert_starred_query to accept an optional position parameter. If a position is provided, use it to insert the starred query at the specified location instead of always appending it.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/sentry/discover/endpoints/discover_saved_query_starred.py#L66-L70

Potential issue: The `StarQuerySerializer` accepts an optional `position` field, but the
endpoint logic silently ignores it. The code only reads the `is_starred` value from the
validated serializer data and never extracts or uses the `position`. The call to
`DiscoverSavedQueryStarredManager.insert_starred_query` does not pass a position;
instead, the underlying method always calculates a new position by calling
`next_starred_position`. This results in any client-provided `position` being
disregarded, and the starred query is always appended to the end of the list, leading to
unexpected ordering behavior.

@lzhao-sentry lzhao-sentry Sep 9, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not an issue because clients arent ordering the queries on creation, it's done automatically by insert_starred_query

@lzhao-sentry
lzhao-sentry merged commit 784f9dd into master Sep 9, 2026
78 of 80 checks passed
@lzhao-sentry
lzhao-sentry deleted the lzhao/feat/discover-saved-query-endpoint branch September 9, 2026 19:16
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