Bugfix: variable definition for different actions

This commit is contained in:
Vivek Santayana 2022-08-20 12:59:26 +01:00
parent 72f2af1df8
commit 2bf0eeb33d

View File

@ -80,10 +80,8 @@ def _submit_quiz():
def _editor(id:str=None): def _editor(id:str=None):
request_data = request.get_json() request_data = request.get_json()
id = request_data['id'] id = request_data['id']
try: try: dataset = Dataset.query.filter_by(id=id).first()
dataset = Dataset.query.filter_by(id=id).first() except (SQLAlchemyError, ConnectionError) as exception:
user = User.query.filter_by(id=creator).first()
except SQLAlchemyError as exception:
write('system.log', f'Database error when processing request \'{request.url}\': {exception}') write('system.log', f'Database error when processing request \'{request.url}\': {exception}')
return abort(500) return abort(500)
if not dataset: return jsonify({'error': 'Invalid request. Dataset not found.'}), 404 if not dataset: return jsonify({'error': 'Invalid request. Dataset not found.'}), 404
@ -94,6 +92,10 @@ def _editor(id:str=None):
return jsonify({'success': 'Successfully downloaded dataset', 'data': data}), 200 return jsonify({'success': 'Successfully downloaded dataset', 'data': data}), 200
default = request_data['default'] default = request_data['default']
creator = request_data['creator'] creator = request_data['creator']
try: user = User.query.filter_by(id=creator).first()
except (SQLAlchemyError, ConnectionError) as exception:
write('system.log', f'Database error when processing request \'{request.url}\': {exception}')
return abort(500)
name = request_data['name'] name = request_data['name']
data = request_data['data'] data = request_data['data']
if not validate_json(data): return jsonify({'error': 'The data you submitted was invalid.'}), 400 if not validate_json(data): return jsonify({'error': 'The data you submitted was invalid.'}), 400