Skip to content

fix(replays): Guard against IndexError in query processing with leading logical operators#116117

Draft
sentry[bot] wants to merge 1 commit into
masterfrom
seer/fix/replays-query-indexerror
Draft

fix(replays): Guard against IndexError in query processing with leading logical operators#116117
sentry[bot] wants to merge 1 commit into
masterfrom
seer/fix/replays-query-indexerror

Conversation

@sentry
Copy link
Copy Markdown
Contributor

@sentry sentry Bot commented May 24, 2026

This PR addresses an IndexError: list index out of range occurring in src/sentry/replays/usecases/query/__init__.py within the attempt_compressed_condition function.

The root cause was that attempt_compressed_condition would unconditionally access result[-1] without checking if result was empty. This became an issue when handle_search_filters processed search_filters lists that began with a logical operator like 'AND' or 'OR'. In such cases, the look_back variable would be set, leading to a call to attempt_compressed_condition while the result list was still empty, thus triggering the IndexError.

The fix introduces a guard at the beginning of attempt_compressed_condition: if result is empty, the condition is simply appended, and the function returns. This prevents the IndexError by ensuring result[-1] is only accessed when result is guaranteed to contain at least one element, preserving the existing compression logic for valid scenarios.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Fixes SENTRY-5NH5

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 24, 2026
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.

0 participants