From 7c643ff67bf67b370f8f94154a3587c4f84ab7ee Mon Sep 17 00:00:00 2001 From: Steffen Schuhmann Date: Sun, 29 Mar 2026 15:20:42 +0200 Subject: [PATCH] fix: replace model_validate(..., update=) with .model_copy(update=) Pydantic v2 model_validate() does not accept an update kwarg; the correct pattern is model_validate(obj).model_copy(update={...}). Co-Authored-By: Claude Sonnet 4.6 --- api/src/rehearsalhub/routers/sessions.py | 6 +++--- api/src/rehearsalhub/routers/songs.py | 4 ++-- api/src/rehearsalhub/services/nc_scan.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/src/rehearsalhub/routers/sessions.py b/api/src/rehearsalhub/routers/sessions.py index d550d81..2e54b3f 100644 --- a/api/src/rehearsalhub/routers/sessions.py +++ b/api/src/rehearsalhub/routers/sessions.py @@ -34,7 +34,7 @@ async def list_sessions( repo = RehearsalSessionRepository(session) rows = await repo.list_for_band(band_id) return [ - RehearsalSessionRead.model_validate(s, update={"recording_count": count}) + RehearsalSessionRead.model_validate(s).model_copy(update={"recording_count": count}) for s, count in rows ] @@ -58,7 +58,7 @@ async def get_session_detail( raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Session not found") songs = [ - SongRead.model_validate(s, update={"version_count": len(s.versions)}) + SongRead.model_validate(s).model_copy(update={"version_count": len(s.versions)}) for s in rehearsal.songs ] return RehearsalSessionDetail.model_validate( @@ -89,4 +89,4 @@ async def update_session( if updates: rehearsal = await repo.update(rehearsal, **updates) - return RehearsalSessionRead.model_validate(rehearsal, update={"recording_count": 0}) + return RehearsalSessionRead.model_validate(rehearsal).model_copy(update={"recording_count": 0}) diff --git a/api/src/rehearsalhub/routers/songs.py b/api/src/rehearsalhub/routers/songs.py index 1f133d0..dc5d2a7 100644 --- a/api/src/rehearsalhub/routers/songs.py +++ b/api/src/rehearsalhub/routers/songs.py @@ -83,7 +83,7 @@ async def search_songs( unattributed=unattributed, ) return [ - SongRead.model_validate(s, update={"version_count": len(s.versions)}) + SongRead.model_validate(s).model_copy(update={"version_count": len(s.versions)}) for s in songs ] @@ -110,7 +110,7 @@ async def update_song( if updates: song = await song_repo.update(song, **updates) - return SongRead.model_validate(song, update={"version_count": len(song.versions)}) + return SongRead.model_validate(song).model_copy(update={"version_count": len(song.versions)}) @router.post("/bands/{band_id}/songs", response_model=SongRead, status_code=status.HTTP_201_CREATED) diff --git a/api/src/rehearsalhub/services/nc_scan.py b/api/src/rehearsalhub/services/nc_scan.py index 8dc89b8..d06358e 100644 --- a/api/src/rehearsalhub/services/nc_scan.py +++ b/api/src/rehearsalhub/services/nc_scan.py @@ -187,7 +187,7 @@ async def scan_band_folder( ) imported += 1 - read = SongRead.model_validate(song, update={"version_count": 1, "session_id": rehearsal_session_id}) + read = SongRead.model_validate(song).model_copy(update={"version_count": 1, "session_id": rehearsal_session_id}) yield {"type": "song", "song": read.model_dump(mode="json"), "is_new": is_new} yield {