From df909363f52b49a67e32b5b5b82e8d5fc1dfbebc Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Tue, 23 Sep 2025 19:05:50 -0600 Subject: [PATCH] fix: add missing db_session parameter to transcript audio endpoints - Add db_session parameter to transcript_get_audio_mp3 endpoint - Fix audio_mp3_filename path conversion with .as_posix() - Add null check for audio_waveform before returning - Update test fixtures to properly pass db_session parameter - Fix transcript controller calls in test_transcripts_audio_download --- server/reflector/views/transcripts_audio.py | 9 +++++++-- server/tests/conftest.py | 6 +++--- server/tests/test_transcripts_audio_download.py | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/server/reflector/views/transcripts_audio.py b/server/reflector/views/transcripts_audio.py index a16fd9ed..61c06216 100644 --- a/server/reflector/views/transcripts_audio.py +++ b/server/reflector/views/transcripts_audio.py @@ -34,6 +34,7 @@ async def transcript_get_audio_mp3( request: Request, transcript_id: str, user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)], + session: AsyncSession = Depends(get_session), token: str | None = None, ): user_id = user["sub"] if user else None @@ -88,7 +89,7 @@ async def transcript_get_audio_mp3( return range_requests_response( request, - transcript.audio_mp3_filename, + transcript.audio_mp3_filename.as_posix(), content_type="audio/mpeg", content_disposition=f"attachment; filename={filename}", ) @@ -108,4 +109,8 @@ async def transcript_get_audio_waveform( if not transcript.audio_waveform_filename.exists(): raise HTTPException(status_code=404, detail="Audio not found") - return transcript.audio_waveform + audio_waveform = transcript.audio_waveform + if not audio_waveform: + raise HTTPException(status_code=404, detail="Audio waveform not found") + + return audio_waveform diff --git a/server/tests/conftest.py b/server/tests/conftest.py index 7e9c6ba6..c11831c6 100644 --- a/server/tests/conftest.py +++ b/server/tests/conftest.py @@ -345,7 +345,7 @@ def celery_includes(): @pytest.fixture -async def client(): +async def client(db_session): from httpx import AsyncClient from reflector.app import app @@ -364,7 +364,7 @@ def fake_mp3_upload(): @pytest.fixture -async def fake_transcript_with_topics(tmpdir, client): +async def fake_transcript_with_topics(tmpdir, client, db_session): import shutil from pathlib import Path @@ -380,7 +380,7 @@ async def fake_transcript_with_topics(tmpdir, client): assert response.status_code == 200 tid = response.json()["id"] - transcript = await transcripts_controller.get_by_id(tid) + transcript = await transcripts_controller.get_by_id(db_session, tid) assert transcript is not None await transcripts_controller.update(transcript, {"status": "ended"}) diff --git a/server/tests/test_transcripts_audio_download.py b/server/tests/test_transcripts_audio_download.py index e40d0ade..befb3d40 100644 --- a/server/tests/test_transcripts_audio_download.py +++ b/server/tests/test_transcripts_audio_download.py @@ -5,7 +5,7 @@ import pytest @pytest.fixture -async def fake_transcript(tmpdir, client): +async def fake_transcript(tmpdir, client, db_session): from reflector.settings import settings from reflector.views.transcripts import transcripts_controller @@ -16,10 +16,10 @@ async def fake_transcript(tmpdir, client): assert response.status_code == 200 tid = response.json()["id"] - transcript = await transcripts_controller.get_by_id(tid) + transcript = await transcripts_controller.get_by_id(db_session, tid) assert transcript is not None - await transcripts_controller.update(transcript, {"status": "ended"}) + await transcripts_controller.update(db_session, transcript, {"status": "ended"}) # manually copy a file at the expected location audio_filename = transcript.audio_mp3_filename