Skip to content

fix(alerts): raise ValidationError for deprecated sessions dataset#119455

Draft
billyvg wants to merge 1 commit into
masterfrom
claude/serene-cannon-dahwe9-backend
Draft

fix(alerts): raise ValidationError for deprecated sessions dataset#119455
billyvg wants to merge 1 commit into
masterfrom
claude/serene-cannon-dahwe9-backend

Conversation

@billyvg

@billyvg billyvg commented Jul 11, 2026

Copy link
Copy Markdown
Member

Summary

Fixes an unhandled KeyError (SENTRY-5PEF) in the alert rule creation endpoint that surfaces as a 500 error for users attempting to create crash rate alerts with the legacy sessions dataset.

Root cause: validate_dataset in SnubaQueryValidator accepts any valid Dataset enum value — including the deprecated Dataset.Sessions — and passes it along. In _validate_query, line 321 does a dict lookup:

query_type = data.setdefault("query_type", query_datasets_to_type[dataset])

Dataset.Sessions is not in query_datasets_to_type (which maps to alert types), so this raises an unhandled KeyError instead of a user-friendly validation error.

Fix: Add an explicit check for Dataset.Sessions in validate_dataset that raises a clear ValidationError directing users to the metrics dataset for crash rate alerts. This is the correct dataset per the current QUERY_TYPE_VALID_DATASETS mapping (only Dataset.Metrics is valid for CRASH_RATE type).

Evidence from Sentry:

POST /api/0/organizations/{slug}/alert-rules/
aggregate: "percentage(sessions_crashed, sessions)"
dataset: Dataset.Sessions

KeyError: <Dataset.Sessions: 'sessions'>
  File "sentry/snuba/snuba_query_validator.py", line 321
    query_type = data.setdefault("query_type", query_datasets_to_type[dataset])

Session: https://claude.ai/code/session_01J4LcBkJp5FmPYfxmFcq6ZV


Generated by Claude Code

Dataset.Sessions is deprecated but was still accepted by validate_dataset,
causing an unhandled KeyError in _validate_query when looking up
query_datasets_to_type. Now returns a clear deprecation error message
pointing users to the metrics dataset for crash rate alerts instead.

Fixes SENTRY-5PEF

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 11, 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.

2 participants