fix(integrations): Prevent AssertionError in MS Teams webhook for rules without legacy_rule_id - #123703
Draft
sentry[bot] wants to merge 1 commit into
Draft
fix(integrations): Prevent AssertionError in MS Teams webhook for rules without legacy_rule_id#123703sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
…es without legacy_rule_id
Contributor
Backend Test FailuresFailures on
|
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
AssertionErrorthat occurred in the MS Teams webhook when attempting to rebuild an alert card for a rule that did not have alegacy_rule_idexplicitly stored in itsrule.data["actions"].Root Cause:
The
build_rule_urlfunction insentry/integrations/messaging/message_builder.pywas designed to fetch thelegacy_rule_idby callingget_key_from_rule_data(rule, "legacy_rule_id"). However,get_key_from_rule_datacontains a hardassert value is not None, meaning it would raise anAssertionErroriflegacy_rule_idwas 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 tostr(rule.id)) usingget_rule_or_workflow_id.Solution:
build_rule_url: The function now directly acceptsrule_id: stras a parameter, eliminating the internal, unguarded call toget_key_from_rule_data.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-resolvedrule_id(obtained fromget_rule_or_workflow_id) directly tobuild_rule_url.tests/sentry/integrations/msteams/test_message_builder.pyto ensure that card building for rules withoutlegacy_rule_idin their actions data no longer raises anAssertionErrorand 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_idin 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 runThis PR was automatically generated by Sentry. You can adjust this setting at any time.