Skip to content

fix: serialize issue history before merging activities and comments - #9899

Merged
sriramveeraghanta merged 1 commit into
previewfrom
fix/issue-history-sort
Sep 28, 2026
Merged

sriramveeraghanta merged 1 commit into
previewfrom
fix/issue-history-sort

Conversation

@pablohashescobar

@pablohashescobar pablohashescobar commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

Description

When IssueActivityEndpoint is called without activity_type, it merges issue activities and comments into one list sorted by created_at. The sort ran on raw model instances with instance["created_at"], so every request failed with TypeError: 'IssueActivity' object is not subscriptable and returned a 500.

  • Serialize both querysets (IssueActivitySerializer and IssueCommentSerializer) before chain/sorted, so the sort key works on dicts. The response shape now matches the single-type branches.
  • Add a contract test that creates one activity and one comment, then checks for a 200, two rows, and ascending created_at order.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Test Scenarios

  • GET /api/workspaces/<slug>/projects/<project_id>/issues/<issue_id>/history/ with no activity_type returns 200 with activities and comments interleaved in created_at order.
  • ?activity_type=issue-property and ?activity_type=issue-comment still return only activities or only comments.
  • ?created_at__gt=<timestamp> without activity_type returns only newer items, merged and sorted.
  • Contract test: docker compose -f docker-compose-test.yml run --rm api-tests pytest plane/tests/contract/app/test_issue_history_app.py

References

  • No work item ID.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Issue history now displays activities and comments together in chronological order when no activity type is specified.

Covers the merged activity/comment history endpoint, which previously
crashed with a 500 (`TypeError: 'IssueActivity' object is not
subscriptable`) when sorting raw model instances by `created_at`
instead of dict keys.
Copilot AI lite review requested due to automatic review settings September 27, 2026 20:20
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: a75138be-a2e8-45cc-82bf-0d395dcc2e29

📥 Commits

Reviewing files that changed from the base of the PR and between 888b086 and 7a10115.

📒 Files selected for processing (2)
  • apps/api/plane/app/views/issue/activity.py
  • apps/api/plane/tests/contract/app/test_issue_history_app.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The issue history response now sorts serialized activities and comments together. A contract test checks that the endpoint returns both record types in ascending created_at order.

Changes

Issue history response

Layer / File(s) Summary
Serialize and sort history records
apps/api/plane/app/views/issue/activity.py, apps/api/plane/tests/contract/app/test_issue_history_app.py
The response now chains serialized activity and comment data before sorting. The contract test checks for a successful response containing both records in ascending created_at order.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 7a101

The issue history endpoint now returns activities and comments together in creation-time order. No actionable merge-blocking risk remains after normal checks.

🚥 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: serializing issue history before merging activities and comments.
Description check ✅ Passed The description is complete and relevant. It explains the bug, identifies the fix, marks the change type, lists test scenarios, and provides the test command. Screenshots are not applicable, and the l…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

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.

Copilot review overview

🟡 Changes recommended

Adjust the contract test so it fails when merged results are not actually sorted.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes issue-history requests without activity_type by serializing activities and comments before merging and sorting.

Changes:

  • Serialize both querysets before sorting.
  • Add contract coverage for merged history responses.
File Summary
apps/​api/​plane/​tests/​contract/​app/​test_issue_history_app.py Adds merged-history response and ordering coverage; the test should ensure the two sources require reordering.
apps/​api/​plane/​app/​views/​issue/​activity.py Serializes activities and comments before merging and sorting.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +24 to +29
IssueActivity.objects.create(
issue=issue, project=project, workspace=workspace, actor=create_user, verb="created", field="state"
)
IssueComment.objects.create(
issue=issue, project=project, workspace=workspace, actor=create_user, comment_html="<p>hi</p>"
)
@sriramveeraghanta
sriramveeraghanta merged commit c23728e into preview Sep 28, 2026
19 of 20 checks passed
@sriramveeraghanta
sriramveeraghanta deleted the fix/issue-history-sort branch September 28, 2026 21:56
inetshell pushed a commit to HobOps/plane that referenced this pull request Nov 7, 2026
…akeplane#9899)

Covers the merged activity/comment history endpoint, which previously
crashed with a 500 (`TypeError: 'IssueActivity' object is not
subscriptable`) when sorting raw model instances by `created_at`
instead of dict keys.

(cherry picked from commit c23728e)
sriramveeraghanta pushed a commit that referenced this pull request Nov 9, 2026
…9899)

Covers the merged activity/comment history endpoint, which previously
crashed with a 500 (`TypeError: 'IssueActivity' object is not
subscriptable`) when sorting raw model instances by `created_at`
instead of dict keys.

(cherry picked from commit c23728e)
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.

4 participants