1414import logging
1515import os
1616from pathlib import Path
17- from typing import Any , BinaryIO , Sequence
17+ from typing import Any , Sequence
1818
1919from file_retriever import Client , File
2020from sqlmodel import Field , Session , SQLModel , select
@@ -36,8 +36,10 @@ def save(self, id: str, filename: str, content: bytes) -> str:
3636
3737 return str (path )
3838
39- def load (self , reference : str ) -> BinaryIO :
40- return open (reference , "rb" )
39+ def load (self , reference : str ) -> bytes :
40+ with open (reference , "rb" ) as fh :
41+ file = fh .read ()
42+ return file
4143
4244
4345class LocalFileLoader :
@@ -181,21 +183,20 @@ def get(self, id: str | int) -> dict[str, Any] | None:
181183 file = self .session .get (IncomingFileModel , id )
182184 return file .model_dump () if file else None
183185
184- def list (self , workflow_id : str | int ) -> Sequence [dict [str , Any ]]:
186+ def list_by_id (self , id : str | int ) -> Sequence [dict [str , Any ]]:
185187 """
186188 Retrieve all `IncomingFileModel` objects in the database.
187189
188190 Args:
189- workflow_id : the `workflow_id` whose files to retrieve.
191+ id : the `workflow_id` whose files to retrieve.
190192
191193 Returns:
192194 a sequence of `IncomingFileModel` objects.
193195 """
194- statement = select (IncomingFileModel ).where (
195- IncomingFileModel .workflow_id == workflow_id
196- )
197- results = self .session .exec (statement ).all ()
198- return [i .model_dump () for i in results ]
196+ statement = select (IncomingFileModel ).where (IncomingFileModel .workflow_id == id )
197+ results = self .session .exec (statement )
198+ all_files = results .all ()
199+ return [i .model_dump () for i in all_files ]
199200
200201 def save (self , obj : IncomingFileModel ) -> dict [str , Any ]:
201202 """
0 commit comments