From 3415daa7c0ac4150f6afd4fcc72c5da7d8202d5d Mon Sep 17 00:00:00 2001 From: Dicklesworthstone Date: Thu, 30 May 2024 23:26:26 -0400 Subject: [PATCH] Fix --- service_functions.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/service_functions.py b/service_functions.py index 17a3ebe..fb24d2a 100644 --- a/service_functions.py +++ b/service_functions.py @@ -27,6 +27,7 @@ import zstandard as zstd from sqlalchemy import select from sqlalchemy.orm import joinedload +from sqlalchemy.inspection import inspect from fastapi import HTTPException, Request, UploadFile from fastapi.concurrency import run_in_threadpool from typing import List, Optional, Dict, Any @@ -743,6 +744,9 @@ async def download_file(url: str, expected_size: int, expected_hash: str) -> str # Audio Transcript functions start here: +def object_as_dict(obj): + return {c.key: getattr(obj, c.key) for c in inspect(obj).mapper.column_attrs} + async def get_transcript_from_db(audio_file_hash: str) -> Optional[AudioTranscript]: return await execute_with_retry(_get_transcript_from_db, audio_file_hash) @@ -896,8 +900,9 @@ async def get_or_compute_transcript(file: UploadFile, try: existing_audio_transcript = await get_transcript_from_db(audio_file_hash) if existing_audio_transcript: - existing_audio_transcript_dict = existing_audio_transcript.dict() - return AudioTranscriptResponse(**existing_audio_transcript_dict) + # Convert the existing_audio_transcript SQLAlchemy object to a dictionary + existing_audio_transcript_dict = object_as_dict(existing_audio_transcript) + return AudioTranscriptResponse(**existing_audio_transcript_dict) current_position = file.file.tell() file.file.seek(0, os.SEEK_END) audio_file_size_mb = file.file.tell() / (1024 * 1024)