fix(msteams): Prevent AssertionError when rule lacks legacy_rule_id - #120644
Draft
sentry[bot] wants to merge 1 commit into
Draft
fix(msteams): Prevent AssertionError when rule lacks legacy_rule_id#120644sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
Comment on lines
+250
to
+253
| def build_rule_url(rule: Any, group: Group, project: Project, rule_id: str | None = None) -> str: | ||
| org_slug = group.organization.slug | ||
| project_slug = project.slug | ||
| rule_id = get_key_from_rule_data(rule, "legacy_rule_id") | ||
| if rule_id is None: |
Contributor
There was a problem hiding this comment.
build_rule_url fallback still exposes AssertionError for Slack and notification callers
The build_rule_url fallback to get_key_from_rule_data preserves the same AssertionError in Slack build_slack_footer and notification get_notification_title paths, which still call the function without passing the safely resolved rule_id.
Evidence
- build_slack_footer in slack/message_builder/util.py calls get_rule_or_workflow_id(rules[0]) safely, then calls build_rule_url(rules[0], group, project) without the resolved value.
- get_notification_title in notifications/notifications/rules.py follows the same pattern, calling build_rule_url without the resolved value.
- When get_rule_or_workflow_id falls back to str(rule.id), it still returns the "legacy_rule_id" key, causing both callers to enter that match branch.
- build_rule_url then calls get_key_from_rule_data(rule, "legacy_rule_id"), which asserts value is not None and raises AssertionError when the rule data lacks that key.
Identified by Warden · sentry-backend-bugs · 4WC-TWT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an
AssertionErroroccurring in the MS Teams webhook handler (/extensions/msteams/webhook/).The root cause was that
build_rule_urlinsrc/sentry/integrations/messaging/message_builder.pyunconditionally calledget_key_from_rule_data(rule, "legacy_rule_id"). Theget_key_from_rule_datafunction contains an assertion thatvalue is not None, which would fail if therule.data.actions[0]dictionary did not contain thelegacy_rule_idkey. This happened for certain older rules or rules without this specific field set.The
build_footerfunction, which callsbuild_rule_url, already correctly determines the rule ID usingget_rule_or_workflow_id, which includes fallback logic (e.g., tostr(rule.id)).The fix modifies
build_rule_urlto accept the already-resolvedrule_idas a parameter.build_footernow passes this safely resolvedrule_idtobuild_rule_url, thus bypassing the problematic assertion and preventing theAssertionError.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
Comment
@sentry <feedback>on this PR to have Autofix iterate on the changes.