Skip to content

fix(integrations): Prevent AssertionError in MS Teams webhook for rules without legacy_rule_id - #123703

Draft
sentry[bot] wants to merge 1 commit into
masterfrom
seer/fix/msteams-rule-id-assertion-HMte3d
Draft

fix(integrations): Prevent AssertionError in MS Teams webhook for rules without legacy_rule_id#123703
sentry[bot] wants to merge 1 commit into
masterfrom
seer/fix/msteams-rule-id-assertion-HMte3d

Conversation

@sentry

@sentry sentry Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

This PR fixes an AssertionError that occurred in the MS Teams webhook when attempting to rebuild an alert card for a rule that did not have a legacy_rule_id explicitly stored in its rule.data["actions"].

Root Cause:
The build_rule_url function in sentry/integrations/messaging/message_builder.py was designed to fetch the legacy_rule_id by calling get_key_from_rule_data(rule, "legacy_rule_id"). However, get_key_from_rule_data contains a hard assert value is not None, meaning it would raise an AssertionError if legacy_rule_id was missing from the rule's actions data. This was problematic because the calling function, build_footer, already correctly determined the rule ID (with proper fallback to str(rule.id)) using get_rule_or_workflow_id.

Solution:

  1. Refactored build_rule_url: The function now directly accepts rule_id: str as a parameter, eliminating the internal, unguarded call to get_key_from_rule_data.
  2. Updated Callers: build_footer (used by MS Teams) and similar functions in Slack (build_slack_footer) and general notifications (get_notification_title) were updated to pass the already-resolved rule_id (obtained from get_rule_or_workflow_id) directly to build_rule_url.
  3. Regression Test: A new test case was added to tests/sentry/integrations/msteams/test_message_builder.py to ensure that card building for rules without legacy_rule_id in their actions data no longer raises an AssertionError and correctly uses the rule's own ID in the generated URL.

This change ensures that the system gracefully handles rules that may not explicitly store legacy_rule_id in their actions data, preventing crashes during MS Teams card interactions.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Fixes SENTRY-4EPX

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Sep 5, 2026
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on 8ab74d3 in this run:

tests/sentry/integrations/msteams/test_message_builder.py::MSTeamsMessageBuilderTest::test_issue_message_builder_rule_without_legacy_rule_id_in_actionslog
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/integrations/msteams/test_message_builder.py:490: in test_issue_message_builder_rule_without_legacy_rule_id_in_actions
    assert _is_column_set_block(footer)
E   AssertionError: assert False
E    +  where False = _is_column_set_block({'items': [{'actions': [{'card': {'$schema': 'http://adaptivecards.io/schemas/adaptive-card.json', 'actions': [...], '....}, 'title': 'Assign', 'type': <ActionType.SHOW_CARD: 'Action.ShowCard'>}], 'type': 'ActionSet'}], 'type': 'Container'})

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.

0 participants