Skip to content

fix(arithmetic): Improve arithmetic allowlists - #126742

Merged
wmak merged 5 commits into
masterfrom
wmak/fix/improve-arithmetic-allowlists
Oct 9, 2026
Merged

wmak merged 5 commits into
masterfrom
wmak/fix/improve-arithmetic-allowlists

Conversation

@wmak

@wmak wmak commented Oct 7, 2026

Copy link
Copy Markdown
Member
  • Instead of hardcoded allowlists, use the dataset definitions to determine what is and isn't allowed in arithmetic
  • Closes BROWSE-807

- Instead of hardcoded allowlists, use the dataset definitions to
  determine what is and isn't allowed in arithmetic
@wmak
wmak requested review from a team as code owners October 7, 2026 18:19
@linear-code

linear-code Bot commented Oct 7, 2026

Copy link
Copy Markdown

BROWSE-807

@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.

Stale Bugbot comment from a previous run.

Comment thread src/sentry/search/eap/spans/formulas.py Resolved
calculations,
[SimpleNamespace(**param) for param in data["references"]],
resolver.resolve_column,
resolver,

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.

Dummy column fails non-span validation

Medium Severity

Formula save validation substitutes span.duration for every COLUMN parameter, then parse_formula and parse_arithmetic check that result against the dataset allowlist. Logs and metrics definitions do not include span.duration, so saving those formulas with column parameters now fails even when the real columns would be valid.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 366845f. Configure here.

@nsdeschenes nsdeschenes 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.

🚀

Comment on lines +633 to +636
try:
_, _, _ = parse_arithmetic(final_equation, definitions=resolver.definitions)
except ArithmeticError as e:
raise InvalidSearchQuery(e)

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 new parse_arithmetic validation breaks existing saved formulas using functions like trace_status_rate that are not marked with valid_arithmetic=True.
Severity: HIGH

Suggested Fix

Ensure all functions intended for use in formulas, including those from the old hardcoded allowlist like trace_status_rate, are marked with valid_arithmetic=True in their definitions. This will add them to the function_allowlist used by parse_arithmetic and prevent the new validation from incorrectly rejecting valid, existing formulas.

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/search/eap/utils.py#L633-L636

Potential issue: The new validation step `parse_arithmetic(final_equation, ...)` in
`parse_formula` uses a function allowlist derived from definitions with
`valid_arithmetic=True`. However, some existing functions, such as `trace_status_rate`,
were not updated with this flag in the PR. As a result, existing saved formulas that use
these functions (e.g., via references) will now fail this new validation at query time,
raising an `InvalidSearchQuery` error. This is a regression, as these formulas were
previously valid and would execute successfully.

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

@cursor

cursor Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Current version of PR was reviewed by /review-bugbot on Oct 8, 15:17 EDT. It flagged 0 findings.

Bugbot on commit 2c176c0 is skipped.

Comment thread src/sentry/discover/arithmetic.py Resolved

@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.

There are 3 total unresolved issues (including 1 from previous review).

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 e68222f. Configure here.

Comment thread src/sentry/search/eap/resolver.py Resolved
@wmak
wmak merged commit f996a83 into master Oct 9, 2026
87 checks passed
@wmak
wmak deleted the wmak/fix/improve-arithmetic-allowlists branch October 9, 2026 15:28
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.

3 participants