fix: make WorkItemDetail assignees/labels optional for sparse responses#28
Conversation
…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>
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
🧹 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, usingField(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
📒 Files selected for processing (2)
plane/models/work_items.pytests/unit/test_work_item_detail_sparse.py
Summary
WorkItemDetail.assigneesandWorkItemDetail.labelsare changed from required fields to optional with a default of[]fieldsparameter (e.g.,fields=id,name,state), it returns a sparse response that omitsassigneesandlabels, causing a pydanticValidationErrorWorkItemExpand, which already treats these fields as optionalDetails
The fix is a one-line change per field in
plane/models/work_items.py:Test plan
tests/unit/test_work_item_detail_sparse.py:ValidationErrorfields=id,nameresponse worksnameremains a required field (no over-relaxation)🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests