fix: change write to db order (#35948)

This commit is contained in:
wangxiaolei 2026-05-09 10:36:54 +08:00 committed by GitHub
parent 271019006e
commit c74cbb68da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -107,15 +107,14 @@ 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()
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