Skip to content

Conversation

@vamsikrishnamathala
Copy link
Member

@vamsikrishnamathala vamsikrishnamathala commented Aug 28, 2025

Description

This PR fixes an issue with state validation in draft issues where the project context was not being properly maintained during updates. The changes ensure consistent state validation behaviour between regular issues and draft issues.

  • Fixed project_id context handling in DraftIssueCreateSerializer for partial updates
  • Added fallback to existing issue's project_id when no new project_id is provided in the request
  • Ensures state validation uses the correct project context for both new and updated draft issues

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)

Screen.Recording.2025-08-28.at.2.31.43.PM.mov

Summary by CodeRabbit

  • Bug Fixes
    • Resolved an issue where updating a draft issue could pass a null project to validation, triggering errors. The update now reliably uses the provided project or the issue’s current project, preventing 400 responses and ensuring correct association during partial updates. This improves reliability when changing projects or leaving them unchanged; no UI changes required.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 28, 2025

Walkthrough

Adds project_id fallback logic in DraftIssue partial_update: uses request.data project_id if provided, else the issue’s existing project_id when building serializer context. No signature changes; response codes and overall flow unchanged.

Changes

Cohort / File(s) Summary of Changes
Workspace Draft Issue Update
apps/api/plane/app/views/workspace/draft.py
In partial_update, derive local project_id = request.data.get("project_id", issue.project_id) and pass it into DraftIssueCreateSerializer context. Retains existing cycle_id handling and response flow (404/204/400). No public API changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant V as DraftView.partial_update
  participant DB as DB: Issue
  participant S as DraftIssueCreateSerializer

  C->>V: PATCH /workspaces/{slug}/drafts/{pk}
  V->>DB: Fetch Issue by pk
  alt Issue not found
    V-->>C: 404 Not Found
  else Issue found
    V->>V: project_id = request.data.project_id or issue.project_id
    V->>S: Instantiate with context{ project_id, cycle_id }
    S->>S: validate()
    alt valid
      S->>DB: save()
      V-->>C: 204 No Content
    else invalid
      V-->>C: 400 Bad Request (errors)
    end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

requires approval

Suggested reviewers

  • dheeru0198

Poem

A hop and a bop through project fields,
I choose the ID the payload yields—
Or keep the one the issue knows,
So drafts can flow where logic goes.
Ears up, paws down, I test and run—
Patch applied; consistency won! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-draft_state_update

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@makeplane
Copy link

makeplane bot commented Aug 28, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/api/plane/app/views/workspace/draft.py (1)

182-184: Consider passing workspace_id in context for parity and future-proofing.

Not strictly required per current validators, but cheap and keeps parity with create(). Low risk since it’s read-only for update flows.

             context={
-                "project_id": project_id,
+                "project_id": context_project_id,
+                "workspace_id": issue.workspace_id,
                 "cycle_id": request.data.get("cycle_id", "not_provided"),
             },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ddeabee and 7edf93a.

📒 Files selected for processing (1)
  • apps/api/plane/app/views/workspace/draft.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: NarayanBavisetti
PR: makeplane/plane#7460
File: apps/api/plane/app/serializers/draft.py:112-122
Timestamp: 2025-07-23T18:18:06.875Z
Learning: In the Plane codebase serializers, workspace_id is not consistently passed in serializer context, so parent issue validation in DraftIssueCreateSerializer only checks project_id rather than both workspace_id and project_id. The existing project member authentication system already validates that users can only access projects they belong to, providing sufficient security without risking breaking functionality by adding workspace_id validation where the context might not be available.
📚 Learning: 2025-07-23T18:18:06.875Z
Learnt from: NarayanBavisetti
PR: makeplane/plane#7460
File: apps/api/plane/app/serializers/draft.py:112-122
Timestamp: 2025-07-23T18:18:06.875Z
Learning: In the Plane codebase serializers, workspace_id is not consistently passed in serializer context, so parent issue validation in DraftIssueCreateSerializer only checks project_id rather than both workspace_id and project_id. The existing project member authentication system already validates that users can only access projects they belong to, providing sufficient security without risking breaking functionality by adding workspace_id validation where the context might not be available.

Applied to files:

  • apps/api/plane/app/views/workspace/draft.py
🧬 Code graph analysis (1)
apps/api/plane/app/views/workspace/draft.py (2)
apps/api/plane/tests/unit/bg_tasks/test_copy_s3_objects.py (1)
  • issue (25-31)
apps/api/plane/app/serializers/draft.py (1)
  • DraftIssueCreateSerializer (31-309)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
apps/api/plane/app/views/workspace/draft.py (1)

167-185: Ignore cross-project mismatch concern in partial_update. The serializer’s update method always uses instance.project_id for all related writes, so any user-supplied project_id in the context is never applied—no cross-project integrity issue.

Likely an incorrect or invalid review comment.

@sriramveeraghanta sriramveeraghanta merged commit 3b3bd3e into preview Aug 28, 2025
6 of 9 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix-draft_state_update branch August 28, 2025 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants