Skip to content

fix(api): add the documented work item relation removal endpoint - #9585

Open
mggarofalo wants to merge 3 commits into
makeplane:previewfrom
mggarofalo:fix/9584-work-item-relation-remove-endpoint
Open

mggarofalo wants to merge 3 commits into
makeplane:previewfrom
mggarofalo:fix/9584-work-item-relation-remove-endpoint

Conversation

@mggarofalo

@mggarofalo mggarofalo commented Aug 11, 2026 •

Copy link
Copy Markdown

Description

The API reference documents a work-item relation removal endpoint:

POST /api/v1/workspaces/{workspace_slug}/projects/{project_id}/work-items/{work_item_id}/relations/remove/
{"related_issue": "<uuid>"}

but that route was never registered, so it returns 404 on every instance. Relations can be created and listed through the public API and never removed, which leaves an integration able to build a dependency graph but unable to correct it. The only working path is the internal app API (POST /api/workspaces/.../issues/{id}/remove-relation/), which uses BaseSessionAuthentication and so rejects an X-API-Key — unusable server-to-server.

This registers the documented route so the docs page and the code agree.

What changed

  • apps/api/plane/api/views/issue.py — new IssueRelationRemoveAPIEndpoint. It consumes IssueRelationRemoveSerializer, which was already written with the exact request shape from the docs page but was never imported or referenced by anything.
  • apps/api/plane/api/urls/work_item.py — registers .../work-items/<issue_id>/relations/remove/ under the work-items prefix the docs advertise, next to the existing relations/ list/create route.
  • apps/api/plane/api/serializers/__init__.py, apps/api/plane/api/views/__init__.py — export the serializer and the endpoint.
  • apps/api/plane/tests/conftest.py (second commit) — ApiKeyRateThrottle counts requests per API key in the shared cache, and every contract test authenticates with the same token, so the history accumulated across the whole session. Once the suite crossed 60 requests inside a minute, whichever tests ran next were rate limited into 429s regardless of what they asserted — adding tests anywhere could break tests elsewhere, which is exactly what happened when the tests below were added. The api_key_client fixture now clears the token's throttle history so each test starts with the full budget.

Behaviour of the new endpoint

  • The relation is matched in either direction. blocked_by is stored once, so a work item on the blocking side has to match on related_issue_id rather than issue_id; the same request body works from either end.
  • Matching is scoped to the workspace, not the project, because relations may cross projects — the same scope the list/create endpoint uses.
  • The work item in the path must belong to the project in the path, otherwise membership of that project would not actually authorize removing relations of work items in projects the caller cannot see. A mismatch is a 404.
  • A relation that does not exist is a 404, not a 500.
  • A pair with relations stored in both directions — e.g. A blocked_by B and B relates_to A are two distinct rows, both permitted by the unique constraint on the directed pair — removes the most recently created one. The documented request body carries no relation_type to disambiguate with, so this matches what the app API already does.
  • Removal dispatches issue_relation.activity.deleted with notification=True, matching what the web app does. The stored relation is directional, so the relation type is reported as seen from the work item in the path (a stored blocked_by whose related_issue is the path item is reported as blocking) — otherwise the activity entries on the two work items read the wrong way round.
  • Returns 204 No Content with an empty body, as documented.

The OpenAPI schema is generated from the views, so the endpoint now appears in the generated reference under Work Item Relations with operation id remove_work_item_relation.

Type of Change

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

Test Scenarios

New contract tests in apps/api/plane/tests/contract/api/test_work_item_relations.py (9 tests, all passing):

  • removing a relation returns 204 and deletes it
  • a relation stored in the reverse direction is removable from either side
  • a relation that crosses projects is removable
  • a relation that does not exist returns 404
  • a work item that does not belong to the project in the path returns 404 and leaves the relation intact
  • a missing related_issue returns 400
  • a malformed (non-UUID) related_issue returns 400
  • removal dispatches issue_relation.activity.deleted with notification=True and the relation type as seen from the path work item
  • a full round trip — create, list, remove, list — using only the documented public endpoints

Run with:

docker compose -f docker-compose-test.yml run --rm api-tests pytest plane/tests/contract/api/test_work_item_relations.py

The full suite passes — 525 tests, run twice back to back to confirm the throttle history no longer leaks between tests:

docker compose -f docker-compose-test.yml run --rm api-tests pytest plane/tests

The generated OpenAPI schema was checked too (ENABLE_DRF_SPECTACULAR=1 python manage.py spectacular): the endpoint appears at the documented path under the Work Item Relations tag with operationId: remove_work_item_relation, an IssueRelationRemoveRequest body and 204/400/401/403/404 responses, and adds no new schema warnings.

ruff check and ruff format are clean on every file touched.

Out of scope

IssueRelationViewSet.remove_relation on the app API has the same .first() → .delete() crash (AttributeError → HTTP 500 when the relation does not exist). That is already fixed in #9531 (SECUR-243), which touches the same handler to bind the URL work item to the URL project, so it is deliberately left out here rather than carried in both branches. Nothing in this PR depends on it — the new public endpoint has its own 404 and does not share that code path.

References

Closes #9584

Summary by CodeRabbit

  • New Features
    • Added the ability to remove relationships between work items through the API.
    • Supports removing relationships regardless of their direction, with project and workspace validation.
    • Records activity when a relationship is removed.
  • Bug Fixes
    • Improved test isolation by clearing API key rate-limit state between tests.
  • Tests
    • Added coverage for valid removals, missing or invalid requests, cross-project relationships, and complete relationship workflows.

The API reference documents

  POST /api/v1/workspaces/{slug}/projects/{project_id}/work-items/{id}/relations/remove/

but the route was never registered, so it returned 404 everywhere.
Relations could be created and listed through the public API but never
removed, leaving integrations unable to correct a dependency graph. The
only working path was the internal app API, which uses session auth and
rejects an API key.

Register the documented route against a new IssueRelationRemoveAPIEndpoint,
which consumes the already-written but unreferenced
IssueRelationRemoveSerializer. The relation is matched in either direction
and scoped to the workspace, since relations may cross projects. The work
item in the path must belong to the project in the path, so membership of
that project actually authorizes the removal.

A relation that does not exist is a 404 rather than an AttributeError on
None -> 500. Fix the same latent crash in
IssueRelationViewSet.remove_relation on the app API.

Removal dispatches issue_relation.activity.deleted with notification=True,
reporting the relation type as seen from the work item in the path so the
activity feed on both work items reads the right way round.

Closes makeplane#9584
ApiKeyRateThrottle counts requests per API key in the shared cache, and
every contract test authenticates with the same token, so the history
accumulated across the session. Once the suite crossed 60 requests inside
a minute, whichever tests happened to run next were rate limited into 429s
regardless of what they asserted -- so adding tests anywhere could break
tests elsewhere.

Clear the token's throttle history in the api_key_client fixture so each
test starts with the full budget.
@CLAassistant

CLAassistant commented Aug 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Aug 11, 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 Plus

Run ID: 4ecda52d-54b5-4cad-8324-8758d22780f2

📥 Commits

Reviewing files that changed from the base of the PR and between 012cab6 and e0c3fcd.

📒 Files selected for processing (1)
  • apps/api/plane/tests/contract/api/test_work_item_relations.py
💤 Files with no reviewable changes (1)
  • apps/api/plane/tests/contract/api/test_work_item_relations.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Adds the documented public POST endpoint for removing work-item relations. The endpoint validates scope and input, handles direct and reverse relations, records deletion activity, and returns HTTP 204. Contract tests cover successful, invalid, scoped, and round-trip cases.

Changes

Work-item relation removal

Layer / File(s) Summary
Public removal route and exports
apps/api/plane/api/serializers/__init__.py, apps/api/plane/api/urls/work_item.py, apps/api/plane/api/views/__init__.py
Exports the removal serializer and endpoint. Registers the POST /work-items/<issue_id>/relations/remove/ route.
Relation removal endpoint behavior
apps/api/plane/api/views/issue.py
Validates related_issue, checks project and workspace scope, finds relations in either direction, deletes the relation, records deletion activity, and returns 404 or 204 responses.
Removal contract validation
apps/api/plane/tests/conftest.py, apps/api/plane/tests/contract/api/test_work_item_relations.py
Adds fixtures and contract coverage for successful removal, reverse and cross-project relations, invalid input, activity dispatch, throttling isolation, and the create-read-remove flow.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to e0c3f

This change adds the documented relation-removal endpoint with validated 204/400/404 behavior and no actionable merge-blocking risk remains.

Suggested reviewers: dheeru0198, pablohashescobar

Sequence Diagram(s)

sequenceDiagram
  participant APIClient
  participant IssueRelationRemoveAPIEndpoint
  participant IssueRelation
  participant DeletionActivity
  APIClient->>IssueRelationRemoveAPIEndpoint: POST related_issue
  IssueRelationRemoveAPIEndpoint->>IssueRelation: Find and delete matching relation
  IssueRelationRemoveAPIEndpoint->>DeletionActivity: Record deletion activity
  IssueRelationRemoveAPIEndpoint-->>APIClient: Return 204
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements the documented public removal route and required behavior, including validation, 404 handling, activity dispatch, and API-key tests [#9584].
Out of Scope Changes check ✅ Passed All changes support endpoint delivery or contract-test reliability; no unrelated code changes are evident.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Title check ✅ Passed The title clearly and concisely identifies the main change: adding the documented work-item relation removal endpoint.
Description check ✅ Passed The description covers the change, rationale, behavior, tests, references, type of change, and out-of-scope work in the required template.
✨ 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.

The `.first()` -> `.delete()` crash in `IssueRelationViewSet.remove_relation`
is fixed by makeplane#9531 (SECUR-243), which touches the same handler to bind the URL
issue to the URL project. Carrying the same None check here only conflicts
with it, and the app API is outside the scope of this PR — registering the
documented public v1 removal endpoint.

The new public endpoint keeps its own 404 for a missing relation, so
`test_remove_missing_relation_returns_404` still covers the behaviour.

Also drops two test helper docstrings that restated the method names.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01UVQkY3MCMMuEqhBnTQ9krj
@makeplane

makeplane Bot commented Aug 23, 2026

Copy link
Copy Markdown

Linked to Plane Work Item(s)

References

This comment was auto-generated by Plane

aphelion31 added a commit to aphelion31/saturn that referenced this pull request Nov 11, 2026
aphelion31 added a commit to aphelion31/saturn that referenced this pull request Nov 11, 2026
aphelion31 added a commit to aphelion31/saturn that referenced this pull request Nov 11, 2026
* fix(api): reject non-positive or non-numeric per_page with 400

Refs: makeplane/plane#9429

* fix(api): reject intake issue name over 255 chars with 400

Refs: makeplane/plane#9940

* fix(api): validate work item date ranges on partial updates

Refs: makeplane/plane#9947

* fix(api): reject archiving non-completed or non-cancelled work items

Refs: makeplane/plane#9115

* fix(api): add work item relation removal endpoint

Refs: makeplane/plane#9585

* fix(api): respect completed_at on work item create and patch

Refs: makeplane/plane#9011

* fix(api): require active workspace member as project lead or assignee

Refs: makeplane/plane#10214

* fix(api): honor group_by and normalize aliases in v1 work items list

Refs: makeplane/plane#9765

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.

Docs document a work-item relation removal endpoint that does not exist in the API

2 participants