fix: commit template upload atomically

This commit is contained in:
zwt13703
2026-07-01 21:50:38 +08:00
parent 1ff0fdf602
commit 28f87fbb62
3 changed files with 34 additions and 6 deletions
+3 -2
View File
@@ -34,8 +34,9 @@ def upload_template(
try:
stored_path, content = store_template_file(file)
blocks = parse_document(content)
template = create_template_record(db, name=name, file_path=stored_path, type=type)
save_template_blocks(db, template.id, blocks)
template = create_template_record(db, name=name, file_path=stored_path, type=type, commit=False)
save_template_blocks(db, template.id, blocks, commit=False)
db.commit()
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
except Exception as exc: