Skip to content

[GIT-227] fix: handle missing comment reaction in activity task #9175#9298

Open
CharitSinghChauhan wants to merge 1 commit into
makeplane:previewfrom
CharitSinghChauhan:fix/git-227-comment-reaction-race-condition
Open

[GIT-227] fix: handle missing comment reaction in activity task #9175#9298
CharitSinghChauhan wants to merge 1 commit into
makeplane:previewfrom
CharitSinghChauhan:fix/git-227-comment-reaction-race-condition

Conversation

@CharitSinghChauhan

@CharitSinghChauhan CharitSinghChauhan commented Jun 23, 2026

Copy link
Copy Markdown

Description

Bug

The Celery background task issue_activity crashes with:

TypeError: cannot unpack non-iterable NoneType object

when a comment reaction is deleted before the task processes the corresponding event. This creates a race condition where the CommentReaction record no longer exists by the time the worker executes.

Root Cause

In apps/api/plane/bgtasks/issue_activities_task.py, create_comment_reaction_activity directly unpacks the result of .first():

comment_reaction_id, comment_id = (
    CommentReaction.objects.filter(...)
    .values_list("id", "comment__id")
    .first()
)

When the reaction has already been deleted, .first() returns None, causing Python to raise:

TypeError: cannot unpack non-iterable NoneType object

Fix

Store the query result in a temporary variable and return early when no record is found, following the same guard pattern already used in create_issue_reaction_activity:

reaction_data = (
    CommentReaction.objects.filter(...)
    .values_list("id", "comment__id")
    .first()
)

if reaction_data is None:
    return

comment_reaction_id, comment_id = reaction_data

This prevents the Celery task from failing when the reaction no longer exists.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Screenshots and Media

N/A

Test Scenarios

  1. Add a reaction to a comment.
  2. Delete the reaction before the Celery task processes the event.
  3. Verify that the Celery worker logs contain no TypeError traceback.
  4. Verify that other activity events in the same batch continue processing normally.

References

Closes #9175

Summary by CodeRabbit

Bug Fixes

  • Improved stability when processing comment reactions by adding validation to handle edge cases where reaction data might be unavailable.

Copilot AI review requested due to automatic review settings June 23, 2026 16:21
@CLAassistant

CLAassistant commented Jun 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c39a2814-47c1-4654-95c2-d507ca1b6c20

📥 Commits

Reviewing files that changed from the base of the PR and between 6c9dbb5 and 95c2e59.

📒 Files selected for processing (1)
  • apps/api/plane/bgtasks/issue_activities_task.py

📝 Walkthrough

Walkthrough

In create_comment_reaction_activity, the CommentReaction query result is now stored in a reaction_data variable before unpacking. An explicit None check returns early from the function when no matching reaction row is found, preventing a TypeError on unpack.

Changes

Comment Reaction Null Guard

Layer / File(s) Summary
Early-return guard in create_comment_reaction_activity
apps/api/plane/bgtasks/issue_activities_task.py
Assigns .values_list(...).first() to reaction_data, returns early if reaction_data is None, and unpacks (comment_reaction_id, comment_id) only when a row exists.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇 Hop, hop — no crash today!
A reaction went missing, but that's okay.
We check for None before we unpack,
The Celery task stays right on track.
No TypeError lurking in the night —
Just a gentle return, and all is right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly indicates it addresses a bug fix for handling missing comment reactions in the activity task, which matches the primary change in the code.
Description check ✅ Passed The PR description is comprehensive and includes all required template sections: detailed description of the bug, type of change (bug fix), test scenarios, and references to issue #9175.
Linked Issues check ✅ Passed The PR fully addresses issue #9175 by implementing a guard pattern to handle missing comment reactions gracefully, preventing the TypeError crash when a reaction no longer exists.
Out of Scope Changes check ✅ Passed The changes are focused solely on fixing the race condition in create_comment_reaction_activity and do not introduce any out-of-scope modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@makeplane

makeplane Bot commented Jun 23, 2026

Copy link
Copy Markdown

Linked to Plane Work Item(s)

This comment was auto-generated by Plane

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a race-condition crash in the issue_activity Celery background task when a comment reaction is deleted before the corresponding activity event is processed. The change makes create_comment_reaction_activity resilient to missing CommentReaction rows by guarding against a None query result.

Changes:

  • Avoid unpacking a None result from .values_list(...).first() by storing the tuple first.
  • Return early when the reaction record is not found, preventing the task from crashing and allowing the batch to continue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comment Reaction Activity Crashes Celery Task When Reaction Not Found

3 participants