Skip to content

fix(combinators): Handle equations in migration - #126768

Merged
wmak merged 1 commit into
masterfrom
wmak/fix/handle-equations-in-if-migration
Oct 7, 2026
Merged

wmak merged 1 commit into
masterfrom
wmak/fix/handle-equations-in-if-migration

Conversation

@wmak

@wmak wmak commented Oct 7, 2026

Copy link
Copy Markdown
Member
  • Wasn't handling equations in the migration so it'd hit an equation and fail
  • Fixes SENTRY-5XR5

- Wasn't handling equations in the migration so it'd hit an equation and
  fail
- Fixes SENTRY-5XR5
@wmak
wmak requested a review from a team as a code owner October 7, 2026 19:50
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 7, 2026

@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 1 potential issue.

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 27575e1. Configure here.

continue
if (rewritten := _rewrite_if_aggregate(func)) is not None:
updated = updated.replace(func, rewritten)
changed = True

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.

Substring replace corrupts equation rewrites

High Severity

updated.replace rewrites every occurrence of each _if function string. When one function text is a prefix of another, the shorter match also rewrites the longer call, so the saved equation is corrupted. This migration is one-way, so the damaged query is persisted.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 27575e1. Configure here.

Comment on lines +299 to +301
equation: str,
max_operators: int | None = None,
validate_single_operator: bool = False,

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 data migration silently skips equations that fail to parse, which could result in an incomplete migration with no audit trail.
Severity: MEDIUM

Suggested Fix

Add logging within the except block to record which specific equations failed to parse and why. This will create an audit trail, allowing developers to identify and manually fix any equations that were not automatically migrated.

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/explore/migrations/0016_update_if_syntax_on_spans.py#L299-L301

Potential issue: In the data migration script, equations that fail to parse due to
invalid functions, fields, or syntax are caught and silently skipped by returning
`None`. This prevents the migration from crashing but can lead to an incomplete
migration. Some equations might remain in their old format in the database without any
log or notification indicating that they were not migrated. This lack of an audit trail
for failed transformations is problematic for data integrity.

Did we get this right? 👍 / 👎 to inform future reviews.

@wmak
wmak enabled auto-merge (squash) October 7, 2026 20:33
@wmak
wmak merged commit 70f965e into master Oct 7, 2026
89 of 90 checks passed
@wmak
wmak deleted the wmak/fix/handle-equations-in-if-migration branch October 7, 2026 20:36
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