1010from uuid import uuid4
1111
1212import httpx
13+ from sqlalchemy import select
1314from sqlalchemy .orm import Session
1415
1516from configs import dify_config
@@ -158,13 +159,7 @@ def get_file_binary(self, id: str) -> Union[tuple[bytes, str], None]:
158159 :return: the binary of the file, mime type
159160 """
160161 with Session (self ._engine , expire_on_commit = False ) as session :
161- tool_file : ToolFile | None = (
162- session .query (ToolFile )
163- .where (
164- ToolFile .id == id ,
165- )
166- .first ()
167- )
162+ tool_file : ToolFile | None = session .scalars (select (ToolFile ).where (ToolFile .id == id ).limit (1 )).first ()
168163
169164 if not tool_file :
170165 return None
@@ -182,13 +177,9 @@ def get_file_binary_by_message_file_id(self, id: str) -> Union[tuple[bytes, str]
182177 :return: the binary of the file, mime type
183178 """
184179 with Session (self ._engine , expire_on_commit = False ) as session :
185- message_file : MessageFile | None = (
186- session .query (MessageFile )
187- .where (
188- MessageFile .id == id ,
189- )
190- .first ()
191- )
180+ message_file : MessageFile | None = session .scalars (
181+ select (MessageFile ).where (MessageFile .id == id ).limit (1 )
182+ ).first ()
192183
193184 # Check if message_file is not None
194185 if message_file is not None :
@@ -202,13 +193,9 @@ def get_file_binary_by_message_file_id(self, id: str) -> Union[tuple[bytes, str]
202193 else :
203194 tool_file_id = None
204195
205- tool_file : ToolFile | None = (
206- session .query (ToolFile )
207- .where (
208- ToolFile .id == tool_file_id ,
209- )
210- .first ()
211- )
196+ tool_file : ToolFile | None = session .scalars (
197+ select (ToolFile ).where (ToolFile .id == tool_file_id ).limit (1 )
198+ ).first ()
212199
213200 if not tool_file :
214201 return None
@@ -226,13 +213,9 @@ def get_file_generator_by_tool_file_id(self, tool_file_id: str) -> tuple[Optiona
226213 :return: the binary of the file, mime type
227214 """
228215 with Session (self ._engine , expire_on_commit = False ) as session :
229- tool_file : ToolFile | None = (
230- session .query (ToolFile )
231- .where (
232- ToolFile .id == tool_file_id ,
233- )
234- .first ()
235- )
216+ tool_file : ToolFile | None = session .scalars (
217+ select (ToolFile ).where (ToolFile .id == tool_file_id ).limit (1 )
218+ ).first ()
236219
237220 if not tool_file :
238221 return None , None
0 commit comments