Repository navigation
fix(api): add the documented work item relation removal endpoint - #9585
mggarofalo wants to merge 3 commits into
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughAdds 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. ChangesWork-item relation removal
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This change adds the documented relation-removal endpoint with validated 204/400/404 behavior and no actionable merge-blocking risk remains. Suggested reviewers: 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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
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
|
Linked to Plane Work Item(s) References This comment was auto-generated by Plane |
* 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
Description
The API reference documents a work-item relation removal endpoint:
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 usesBaseSessionAuthenticationand so rejects anX-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— newIssueRelationRemoveAPIEndpoint. It consumesIssueRelationRemoveSerializer, 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 thework-itemsprefix the docs advertise, next to the existingrelations/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) —ApiKeyRateThrottlecounts 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. Theapi_key_clientfixture now clears the token's throttle history so each test starts with the full budget.Behaviour of the new endpoint
blocked_byis stored once, so a work item on theblockingside has to match onrelated_issue_idrather thanissue_id; the same request body works from either end.A blocked_by BandB relates_to Aare two distinct rows, both permitted by the unique constraint on the directed pair — removes the most recently created one. The documented request body carries norelation_typeto disambiguate with, so this matches what the app API already does.issue_relation.activity.deletedwithnotification=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 storedblocked_bywhoserelated_issueis the path item is reported asblocking) — otherwise the activity entries on the two work items read the wrong way round.204 No Contentwith 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
Test Scenarios
New contract tests in
apps/api/plane/tests/contract/api/test_work_item_relations.py(9 tests, all passing):related_issuereturns 400related_issuereturns 400issue_relation.activity.deletedwithnotification=Trueand the relation type as seen from the path work itemRun with:
The full suite passes — 525 tests, run twice back to back to confirm the throttle history no longer leaks between 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 withoperationId: remove_work_item_relation, anIssueRelationRemoveRequestbody and 204/400/401/403/404 responses, and adds no new schema warnings.ruff checkandruff formatare clean on every file touched.Out of scope
IssueRelationViewSet.remove_relationon 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