From 07a4720b6897bf7d0a1e1331961554a8f99a47af Mon Sep 17 00:00:00 2001 From: fatelei Date: Sat, 9 May 2026 09:58:20 +0800 Subject: [PATCH] fix: change write to db order --- api/services/file_service.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/api/services/file_service.py b/api/services/file_service.py index f60afe2f19..e243e2e288 100644 --- a/api/services/file_service.py +++ b/api/services/file_service.py @@ -107,15 +107,16 @@ class FileService: hash=hashlib.sha3_256(content).hexdigest(), source_url=source_url, ) - # The `UploadFile` ID is generated within its constructor, so flushing to retrieve the ID is unnecessary. - # We can directly generate the `source_url` here before committing. - if not upload_file.source_url: - upload_file.source_url = file_helpers.get_signed_file_url(upload_file_id=upload_file.id) with self._session_maker(expire_on_commit=False) as session: session.add(upload_file) session.commit() + # The `UploadFile` ID is generated within its constructor, so flushing to retrieve the ID is unnecessary. + # We can directly generate the `source_url` here before committing. + if not upload_file.source_url: + upload_file.source_url = file_helpers.get_signed_file_url(upload_file_id=upload_file.id) + return upload_file @staticmethod