LinkDesk/backend/docs/task-18-schema-fix.md

61 lines
2.4 KiB
Markdown

# Task 18: Schema Fix for Custom Status Support
## Issue
The backend was throwing a validation error when trying to return custom task statuses:
```
pydantic_core._pydantic_core.ValidationError: 1 validation error for TaskStatusInfo
status
Input should be 'not_started', 'in_progress', 'submitted', 'approved' or 'retake' [type=enum, input_value='custom_ready', input_type=str]
```
## Root Cause
The `TaskStatusInfo` schema in both `backend/schemas/asset.py` and `backend/schemas/shot.py` was still using the `TaskStatus` enum for the `status` field, which only accepts the five system statuses.
## Fix Applied
### backend/schemas/asset.py
Changed the `status` field from `TaskStatus` enum to `str`:
```python
class TaskStatusInfo(BaseModel):
task_type: str # Changed from TaskType enum to str to support custom task types
status: str # Changed from TaskStatus enum to str to support custom statuses
task_id: Optional[int] = None
assigned_user_id: Optional[int] = None
```
### backend/schemas/shot.py
Changed the `status` field from `TaskStatus` enum to `str`:
```python
class TaskStatusInfo(BaseModel):
"""Task status information for table display"""
task_type: str # String to support custom task types
status: str # Changed from TaskStatus enum to str to support custom statuses
task_id: Optional[int] = None
assigned_user_id: Optional[int] = None
```
### backend/schemas/task.py
Changed the `status` field from `TaskStatus` enum to `str` in `TaskListResponse`:
```python
class TaskListResponse(BaseModel):
id: int
name: str
task_type: str # Changed from TaskType enum to str to support custom task types
status: str # Changed from TaskStatus enum to str to support custom statuses
deadline: Optional[date] = None
# ... other fields
```
## Impact
- Asset list endpoint (`GET /assets/`) now returns custom statuses correctly
- Shot list endpoint (`GET /shots/`) now returns custom statuses correctly
- Task list endpoint (`GET /tasks/`) now returns custom statuses correctly
- All endpoints can now include custom status IDs in their responses
## Testing
After this fix, the following should work:
1. Create a custom status in a project
2. Assign the custom status to a task
3. View the asset or shot list - the custom status should appear without validation errors
4. The frontend EditableTaskStatus components should display and update custom statuses correctly