CG-17442: Fix DoubleReactException by handling already_reacted Slack API errors #1061
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.
Description
This PR addresses the Sentry issue CODEGEN_MONITORING_PROD-1CHW where a
SlackApiErroris thrown with the error messagealready_reactedwhen trying to add a reaction to a Slack message that already has that reaction.Solution
I've created a new utility function
safe_add_reactionin thecodegen.extensions.slack.utilsmodule that safely adds a reaction to a Slack message, handling the case where the reaction already exists. This function:SlackApiErrorwith thealready_reactederrorThis approach prevents the error from bubbling up and causing the application to crash when a reaction is added multiple times, which can happen due to race conditions or duplicate events from Slack.
Testing
Added comprehensive unit tests for the new utility function, covering:
already_reactederrorNext Steps
To fully resolve this issue, the
show_typing_indicator_slackfunction inapp/modal_app/gen/slack/slack_utils.pyshould be updated to use this new utility function. However, since that file is not in the current codebase, this PR provides the utility function that can be used by that code when it's updated.Related Issues
Fixes CG-17442
💻 View my work • About Codegen