Skip to content

fix(api): return 400 when transferring work items to a cycle that does not exist - #10391

Open
ashokram-si wants to merge 1 commit into
makeplane:previewfrom
ashokram-si:fix/transfer-missing-cycle
Open

ashokram-si wants to merge 1 commit into
makeplane:previewfrom
ashokram-si:fix/transfer-missing-cycle

Conversation

@ashokram-si

@ashokram-si ashokram-si commented Nov 24, 2026 •

Copy link
Copy Markdown

Description

transfer_cycle_issues loaded the target cycle with .first() and then read new_cycle.end_date, so a new_cycle_id that isn't a cycle of the project (deleted, or from another project) raised AttributeError and returned a 500 from both the web app and the public API transfer endpoints. It now returns "Target cycle not found", next to the existing "Source cycle not found" check, which both endpoints already answer with a 400.

Type of Change

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

Test Scenarios

apps/api/plane/tests/contract/app/test_cycle_transfer_missing_cycle_app.py: a random id and a cycle of another project both give a 400 with "Target cycle not found", and the source cycle's progress snapshot is left untouched. Both fail on preview with a 500.

References

Fixes #10390

Summary by CodeRabbit

  • Bug Fixes
    • Fixed cycle transfers to unavailable or unrelated destination cycles. These requests now return a clear error instead of causing an unexpected failure.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The transfer utility now returns a failure response when the destination cycle lookup finds no cycle. Contract tests cover nonexistent and cross-project target IDs. They assert HTTP 400, and the nonexistent-target test checks the error message and unchanged source-cycle progress snapshot.

Changes: Cycle transfer validation

Layer / File(s) Summary
Target cycle check and contract coverage
apps/api/plane/utils/cycle_transfer_issues.py, apps/api/plane/tests/contract/app/test_cycle_transfer_missing_cycle_app.py
The transfer utility returns a failure response when no destination cycle matches the lookup. Contract tests assert HTTP 400 for nonexistent and cross-project targets. The nonexistent-target test also checks the error message and source cycle’s progress snapshot.

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

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · up to 50420

Transferring work items to a missing or out-of-project cycle now returns a clear 400 error instead of a server error. The change is small and contained, and I found no remaining merge risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: transfers to a nonexistent target cycle now return HTTP 400 instead of failing. It matches the code change that adds a "Target cycle not found" check in transfer_cycle…
Description check Passed The description follows the template. It explains the bug and the fix in detail, and marks the Bug fix type. It describes the test scenarios and links the issue (Fixes #10390). The template's Screensh…
Linked Issues check Passed Issue #10390 requires that a target cycle ID that is not a cycle of the project does not cause a 500. The reviewed head of apps/api/plane/utils/cycle_transfer_issues.py now queries the target with Cyc…
Out of Scope Changes check Passed The changes cover the reported defect. The utility change adds a single guard for the target cycle with a specific error message. The new contract test file exercises the two reproduction cases and ch…
Full details: Title check

Explanation

The title names the main change: transfers to a nonexistent target cycle now return HTTP 400 instead of failing. It matches the code change that adds a "Target cycle not found" check in transfer_cycle_issues and the contract tests for that case. The title uses the conventional fix(api) prefix and is specific.

Full details: Description check

Explanation

The description follows the template. It explains the bug and the fix in detail, and marks the Bug fix type. It describes the test scenarios and links the issue (Fixes #10390). The template's Screenshots section is absent, and the Type of Change list marks only Bug fix. The screenshots section is optional because the change is backend-only, so this gap does not block the check.

Full details: Linked Issues check

Explanation

Issue #10390 requires that a target cycle ID that is not a cycle of the project does not cause a 500. The reviewed head of apps/api/plane/utils/cycle_transfer_issues.py now queries the target with Cycle.objects.filter(workspace__slug=slug, project_id=project_id, pk=new_cycle_id).first(). It returns {"success": False, "error": "Target cycle not found"} when the result is None, before the code reads new_cycle.end_date. This covers both a deleted cycle and a cycle from another project, because the filter is scoped to the workspace and project. The shared function serves both the web app and the public API endpoints. The PR adds contract tests in apps/api/plane/tests/contract/app/test_cycle_transfer_missing_cycle_app.py for a random ID and a cross-project cycle, asserting HTTP 400, the message, and an unchanged source progress snapshot. The base revision of the diff could not be read, so the before-state is taken from the PR summary. The endpoint mapping from success False to HTTP 400 was not inspected directly; the PR description states that the existing Source cycle not found path already returns 400 through the same mechanism.

Full details: Out of Scope Changes check

Explanation

The changes cover the reported defect. The utility change adds a single guard for the target cycle with a specific error message. The new contract test file exercises the two reproduction cases and checks the source cycle snapshot is not modified. No unrelated functional changes were identified in the summary. The base-side diff could not be read, so this verdict relies on the PR summary and the reviewed head file content.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9fae1e83-e953-4e79-9b3f-f3aa2befc32e
Commits

Reviewing files that changed from the base of the PR and between 723bb17 and 50420d3.

Files selected for processing: 2

  • apps/api/plane/tests/contract/app/test_cycle_transfer_missing_cycle_app.py
  • apps/api/plane/utils/cycle_transfer_issues.py

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

This branch has not been deployed

No deployments
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.

[bug]: Transferring work items to a cycle that does not exist returns 500

1 participant