Exception handling for database queries
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from ..models import Dataset
|
||||
from ..tools.logs import write
|
||||
|
||||
from flask import current_app as app
|
||||
from flask import flash, redirect
|
||||
from flask.helpers import url_for
|
||||
from flask.helpers import abort, flash, redirect, url_for
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
@@ -76,7 +77,10 @@ def get_tag_list(dataset:list):
|
||||
def check_dataset_exists(function):
|
||||
@wraps(function)
|
||||
def wrapper(*args, **kwargs):
|
||||
datasets = Dataset.query.all()
|
||||
try: datasets = Dataset.query.all()
|
||||
except SQLAlchemyError as exception:
|
||||
write('system.log', f'Database error when checking existing datasets: {exception}')
|
||||
return abort(500)
|
||||
if not datasets:
|
||||
flash('There are no available question datasets. Please upload a question dataset first, or use the question editor to create a new dataset.', 'error')
|
||||
return redirect(url_for('admin._questions'))
|
||||
|
Reference in New Issue
Block a user