Files
TimeTracker/app
MacJediWizard 89a0897708 fix(api): repair joinedload calls referencing non-existent relationships
Five integration tests fail because three API v1 route groups call
`joinedload()` on relationships the underlying models never define,
producing AttributeError -> 500 on the first query.

The three bad references were all introduced in commit 579fc7af
("extract business logic to service layer", Nov 2025) and have been
quietly broken since. They surfaced only now because the v5.5.6
fixture refresh started exercising these endpoints more thoroughly.
FK enforcement (also added in v5.5.6) is a red herring here.

### Repairs

- `KanbanColumn` has no `project` relationship (only the `project_id`
  FK column), and `KanbanColumn.to_dict()` never reads `self.project`.
  The eager load is dead code in both the PUT/PATCH and DELETE
  handlers — drop it.
- `ClientNote` has an `author` relationship, not `created_by_user`,
  and `ClientNote.to_dict()` reads `self.author.username` /
  `self.author.full_name`. The four call sites still need eager
  loading; rename the attribute to the real one (`author`).
- `SavedFilter` has no `user` relationship (only the `user_id` FK
  column), and `SavedFilter.to_dict()` never reads `self.user`. Like
  KanbanColumn, the eager load is dead code in all four call sites —
  drop it.

### Tests fixed

- tests/test_api_kanban_v1.py::test_kanban_columns
- tests/test_api_client_notes_v1.py::test_client_notes_crud
- tests/test_api_saved_filters_v1.py::test_saved_filters_crud
- tests/test_routes/test_api_v1_invoices_tasks_expenses_refactored.py::TestAPITasksRefactored::test_get_task_uses_eager_loading (transitively, via the same route module)

### Notes

The unused `from sqlalchemy.orm import joinedload` import in the
kanban/saved-filter handlers is left in place to keep the diff
surgical. It can be removed in a follow-up cleanup.

### Test plan

- [ ] pytest tests/test_api_kanban_v1.py::test_kanban_columns
- [ ] pytest tests/test_api_client_notes_v1.py::test_client_notes_crud
- [ ] pytest tests/test_api_saved_filters_v1.py::test_saved_filters_crud
- [ ] All three return 200 from CRUD operations; no AttributeError logged
- [ ] No regression on routes that already used joinedload correctly
2026-05-14 16:54:14 -04:00
..