Skip to content

fix: accept unexpanded id lists for WorkItemDetail assignees/labels#46

Open
hstern wants to merge 1 commit into
makeplane:mainfrom
hstern:fix/work-item-detail-unexpanded-relations
Open

fix: accept unexpanded id lists for WorkItemDetail assignees/labels#46
hstern wants to merge 1 commit into
makeplane:mainfrom
hstern:fix/work-item-detail-unexpanded-relations

Conversation

@hstern
Copy link
Copy Markdown

@hstern hstern commented Jun 3, 2026

Problem

WorkItemDetail types its relations strictly:

assignees: list[UserLite] = Field(default_factory=list)
labels: list[Label] = Field(default_factory=list)

But the Plane API returns assignees and labels as bare UUID strings unless the request explicitly expands them (expand=assignees,labels). So retrieving any assigned or labelled work item without that expand raises:

pydantic_core.ValidationError: 2 validation errors for WorkItemDetail
assignees.0  Input should be a valid dictionary or instance of UserLite
             [input_value='00000000-...', input_type=str]
labels.0     Input should be a valid dictionary or instance of Label
             [input_value='00000000-...', input_type=str]

This makes a plain work_items.retrieve(...) (no expand) fail on real data — e.g. it surfaces through plane-mcp-server's retrieve_work_item_* tools against a self-hosted (CE) instance, where the default serializer returns the unexpanded shape.

Fix

Widen both relations to accept either shape:

assignees: list[str] | list[UserLite] = Field(default_factory=list)
labels: list[str] | list[Label] = Field(default_factory=list)

This mirrors the tolerance the same model already grants state (str | StateLite) and that the sibling WorkItemExpand model already uses for assignees/labels. No behavior change for callers who do expand — those still validate into UserLite/Label objects.

Tests

Adds tests/unit/test_work_item_models.py — pure model-validation tests (no HTTP) covering the unexpanded (bare-ID), expanded (nested-object), and default-empty shapes. The unexpanded case fails on main and passes with this change; the full unit suite stays green.

Summary by CodeRabbit

  • Refactor

    • Enhanced work item models to flexibly accept both compact (ID-only) and expanded (full object) representations of related data in API responses.
  • Tests

    • Added test coverage validating model behavior with both expanded and unexpanded data formats, plus default empty list handling.

WorkItemDetail typed `assignees: list[UserLite]` and `labels: list[Label]`,
but the Plane API returns these relations as bare UUID strings unless the
request expands them (`expand=assignees,labels`). Retrieving any assigned or
labelled work item without that expand therefore raised:

    pydantic_core.ValidationError: ... validation errors for WorkItemDetail
    assignees.0  Input should be a valid dictionary or instance of UserLite
    labels.0     Input should be a valid dictionary or instance of Label

Widen both to `list[str] | list[UserLite]` / `list[str] | list[Label]`,
matching the tolerance `WorkItemDetail.state` (`str | StateLite`) and the
whole `WorkItemExpand` model already grant. Adds pure model-validation unit
tests covering the unexpanded, expanded, and default-empty shapes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

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

Run ID: c116c208-4d37-4a50-98c6-7ddb750b9208

📥 Commits

Reviewing files that changed from the base of the PR and between a105871 and 2832bd3.

📒 Files selected for processing (2)
  • plane/models/work_items.py
  • tests/unit/test_work_item_models.py

📝 Walkthrough

Walkthrough

The PR updates WorkItemDetail in the Plane Python SDK to accept both unexpanded (raw UUID strings) and expanded (nested model objects) forms for assignees and labels fields, reflecting the actual API response behavior depending on query expansion parameters. Comprehensive validation tests ensure both input shapes and defaults function correctly.

Changes

WorkItemDetail flexible relations schema and validation

Layer / File(s) Summary
WorkItemDetail flexible relations schema and validation
plane/models/work_items.py, tests/unit/test_work_item_models.py
WorkItemDetail.assignees and labels fields updated to accept union types (list[str] | list[UserLite] and list[str] | list[Label]) with documentation explaining API expansion behavior. Tests validate both unexpanded UUID-string lists, expanded nested objects, and confirm defaults to empty lists.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A SDK grows more flexible today,
Relations unexpanded or fully on display!
Union types embrace both UUID strings and expanded forms,
Tests verify the duality in every API storm.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: accepting unexpanded ID lists for WorkItemDetail's assignees and labels fields, which directly matches the changeset's primary objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

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.

1 participant