File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change 11import os
22import tempfile
33from app .core .db import engine
4- from sqlmodel import Session
4+ from sqlmodel import Session , select
55import textract
66import requests
77from app .models import Document
@@ -16,7 +16,7 @@ def extract_text_from_file(s3_url: str) -> str:
1616 tmp_file .write (response .content )
1717 tmp_path = tmp_file .name
1818
19- text = textract .process (tmp_path ).decode ("utf-8" )
19+ text = textract .process (tmp_path ).decode ("utf-8" ) or ""
2020
2121 os .remove (tmp_path )
2222
@@ -30,7 +30,9 @@ def extract_text_and_save_to_db(s3_url: str, document_id: str) -> None:
3030 with Session (engine ) as session :
3131 text = extract_text_from_file (s3_url )
3232
33- document = session .query (Document ).filter (Document .id == document_id ).first ()
33+ document_query = select (Document ).where (Document .id == document_id )
34+ document = session .exec (document_query ).first ()
35+
3436 if not document :
3537 raise Exception (f"Document with ID { document_id } not found" )
3638
You can’t perform that action at this time.
0 commit comments