-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix: auto-correct Slack channel names from IDs #105621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix: auto-correct Slack channel names from IDs #105621
Conversation
| # 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 |
There was a problem hiding this comment.
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
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.pyvalidate_slack_entity_id,validate_user_id, andvalidate_channel_idto return the resolved name from the Slack API.src/sentry/integrations/slack/actions/form.pySlackNotifyServiceForm.cleanto use the resolved channel name for auto-correction instead of the user input.#prefix to be dropped.src/sentry/incidents/serializers/alert_rule_trigger_action.pyTesting
New test
test_channel_id_as_channel_name_auto_correctedintest_notify_action.pyto verify ID → name auto-correction.Updated tests
test_channel.pyandtest_organization_alert_rule_details.pyto assert correct auto-correction behavior instead of validation errors.Verification
closes #105478