Skip to content

fix: make WorkItemDetail assignees/labels optional for sparse responses#28

Open
gjenkins20 wants to merge 1 commit intomakeplane:mainfrom
gjenkins20:fix/work-item-detail-optional-assignees-labels
Open

fix: make WorkItemDetail assignees/labels optional for sparse responses#28
gjenkins20 wants to merge 1 commit intomakeplane:mainfrom
gjenkins20:fix/work-item-detail-optional-assignees-labels

Conversation

@gjenkins20
Copy link
Copy Markdown

@gjenkins20 gjenkins20 commented Apr 7, 2026

Summary

  • WorkItemDetail.assignees and WorkItemDetail.labels are changed from required fields to optional with a default of []
  • When the Plane API is called with a fields parameter (e.g., fields=id,name,state), it returns a sparse response that omits assignees and labels, causing a pydantic ValidationError
  • This is consistent with WorkItemExpand, which already treats these fields as optional

Details

The fix is a one-line change per field in plane/models/work_items.py:

# Before (required — fails on sparse responses)
assignees: list[UserLite]
labels: list[Label]

# After (optional with default — works for both full and sparse responses)
assignees: list[UserLite] = []
labels: list[Label] = []

Test plan

  • New unit tests added in tests/unit/test_work_item_detail_sparse.py:
    • Full response with assignees + labels still parses correctly
    • Sparse response without assignees/labels no longer raises ValidationError
    • Minimal fields=id,name response works
    • Explicit empty lists still accepted
    • name remains a required field (no over-relaxation)
  • All 5 new tests pass

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of work item details when API responses contain incomplete data—missing assignees and labels are now treated as empty values instead of causing errors.
  • Tests

    • Added comprehensive test coverage for sparse API response scenarios to ensure robust data handling.

…API responses

When the Plane API is called with the `fields` parameter, it returns only
the requested fields. If `assignees` and `labels` are not in the field list,
the response omits them entirely, causing a pydantic ValidationError.

Default both fields to `[]` so sparse responses parse without error while
preserving identical behavior for full responses.

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

coderabbitai bot commented Apr 7, 2026

📝 Walkthrough

Walkthrough

The WorkItemDetail model in plane/models/work_items.py now provides default empty lists for assignees and labels fields, allowing the model to validate successfully when these fields are absent from sparse API responses. A comprehensive test suite validates this behavior across multiple response formats.

Changes

Cohort / File(s) Summary
Model Default Values
plane/models/work_items.py
Added default empty list ([]) values for assignees and labels fields in WorkItemDetail to support sparse API responses where these fields may be omitted.
Test Coverage
tests/unit/test_work_item_detail_sparse.py
New unit test module with 5 test methods validating WorkItemDetail model parsing for full and sparse API responses, including verification that missing fields default to empty lists and that required fields (name) are still enforced.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Fields now gentle, no longer severe,
Empty lists bloom when data's unclear,
Tests hop and verify, sparse or complete,
Making API responses humble and neat! 🌱

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: making WorkItemDetail's assignees and labels fields optional for handling sparse API responses.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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.

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
plane/models/work_items.py (1)

56-57: Field(default_factory=list) is idiomatic for mutable defaults in Pydantic v2, but not required for safety.

While Pydantic v2 safely deep-copies non-hashable defaults like [] per instance, using Field(default_factory=list) is the clearer, more explicit style. This improves maintainability and aligns with dataclass patterns.

Proposed change
-    assignees: list[UserLite] = []
-    labels: list[Label] = []
+    assignees: list[UserLite] = Field(default_factory=list)
+    labels: list[Label] = Field(default_factory=list)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@plane/models/work_items.py` around lines 56 - 57, The assignees and labels
fields use mutable list literals as defaults; update their declarations to use
Pydantic v2 idiomatic Field(default_factory=list) to make intent explicit and
avoid mutable-default smell—replace the current "assignees: list[UserLite] = []"
and "labels: list[Label] = []" with declarations that call
Field(default_factory=list) for the assignees and labels attributes in the
WorkItem model (or the class that defines these fields).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@plane/models/work_items.py`:
- Around line 56-57: The assignees and labels fields use mutable list literals
as defaults; update their declarations to use Pydantic v2 idiomatic
Field(default_factory=list) to make intent explicit and avoid mutable-default
smell—replace the current "assignees: list[UserLite] = []" and "labels:
list[Label] = []" with declarations that call Field(default_factory=list) for
the assignees and labels attributes in the WorkItem model (or the class that
defines these fields).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 84571490-b447-4d4a-9bda-b3848982fdce

📥 Commits

Reviewing files that changed from the base of the PR and between 72ecc72 and b960262.

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

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