From 8e1e33aa8991477c3141116ab28aa28a324b0c41 Mon Sep 17 00:00:00 2001 From: John Nduli Date: Tue, 24 Sep 2024 09:46:59 +0300 Subject: feat: rollback mysql transaction when rdf insert fails --- gn3/api/metadata_api/wiki.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'gn3') diff --git a/gn3/api/metadata_api/wiki.py b/gn3/api/metadata_api/wiki.py index 8dc4f9a..0fe228f 100644 --- a/gn3/api/metadata_api/wiki.py +++ b/gn3/api/metadata_api/wiki.py @@ -74,13 +74,17 @@ def edit_wiki(comment_id: int): insert_dict["versionId"], cat_id) ) - # Editing RDF: - update_wiki_comment( - insert_dict=insert_dict, - sparql_user=current_app.config["SPARQL_USER"], - sparql_password=current_app.config["SPARQL_PASSWORD"], - sparql_auth_uri=current_app.config["SPARQL_AUTH_URI"] - ) + try: + # Editing RDF: + update_wiki_comment( + insert_dict=insert_dict, + sparql_user=current_app.config["SPARQL_USER"], + sparql_password=current_app.config["SPARQL_PASSWORD"], + sparql_auth_uri=current_app.config["SPARQL_AUTH_URI"] + ) + except Exception as exc: + conn.rollback() + raise exc return jsonify({"success": "ok"}) return jsonify(error="Error editing wiki entry, most likely due to DB error!"), 500 -- cgit v1.2.3