Skip to content

Conversation

@akramcodez
Copy link

Summary

Fixes an issue where Slack alert actions incorrectly saved manually entered channel IDs (e.g., C01234) as display names (e.g., C01234).
The system now validates the ID against the Slack API and automatically replaces it with the correct human-readable channel name (e.g., #general).

Changes

  • src/sentry/integrations/slack/utils/channel.py

    • Updated validate_slack_entity_id, validate_user_id, and validate_channel_id to return the resolved name from the Slack API.
  • src/sentry/integrations/slack/actions/form.py

    • Updated SlackNotifyServiceForm.clean to use the resolved channel name for auto-correction instead of the user input.
    • Fixed a variable scoping bug that caused the # prefix to be dropped.
  • src/sentry/incidents/serializers/alert_rule_trigger_action.py

    • Updated metric alert serializers to support the same auto-correction logic.

Testing

  • New test

    • test_channel_id_as_channel_name_auto_corrected in test_notify_action.py to verify ID → name auto-correction.
  • Updated tests

    • Updated tests in test_channel.py and test_organization_alert_rule_details.py to assert correct auto-correction behavior instead of validation errors.

Verification

  • Verified locally using the full devservices stack (Redis, Snuba, Postgres).

closes #105478

@akramcodez akramcodez requested review from a team as code owners January 3, 2026 08:54
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 3, 2026
Comment on lines +195 to +203
# validate_slack_entity_id returns the actual name from Slack API
# This enables auto-correction when users provide channel IDs as names
actual_slack_name = validate_slack_entity_id(
integration_id=attrs["integration_id"],
input_name=identifier,
input_id=attrs["input_channel_id"],
)
# Store the actual name for use in target_display later
attrs["actual_slack_name"] = actual_slack_name
Copy link

Choose a reason for hiding this comment

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

Bug: The NotificationActionSerializer fails to use the return value from validate_slack_entity_id, preventing auto-correction of Slack channel names from their IDs in the API.
Severity: HIGH | Confidence: High

🔍 Detailed Analysis

The NotificationActionSerializer in notification_action_request.py calls validate_slack_entity_id but does not capture or use its return value. This function was updated to return the actual channel name when a channel ID is provided. While other serializers in the PR correctly use this return value to auto-correct the channel name, this one does not. As a result, if a user provides a Slack channel ID as the target_display when creating or updating a notification action via the API, the ID will be persisted and displayed in the UI instead of the human-readable channel name, defeating the purpose of the auto-correction feature.

💡 Suggested Fix

In notification_action_request.py, capture the return value from the validate_slack_entity_id call. If the returned value is not null, update the target_display in the data dictionary with the corrected channel name before returning it, mirroring the implementation in alert_rule_trigger_action.py.

🤖 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/incidents/serializers/alert_rule_trigger_action.py#L195-L203

Potential issue: The `NotificationActionSerializer` in `notification_action_request.py`
calls `validate_slack_entity_id` but does not capture or use its return value. This
function was updated to return the actual channel name when a channel ID is provided.
While other serializers in the PR correctly use this return value to auto-correct the
channel name, this one does not. As a result, if a user provides a Slack channel ID as
the `target_display` when creating or updating a notification action via the API, the ID
will be persisted and displayed in the UI instead of the human-readable channel name,
defeating the purpose of the auto-correction feature.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 8125783

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.

Issue alerts auto-fills Slack channel with ID

1 participant