Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
fixed server/celery error handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
roll committed Jan 12, 2017
1 parent 99942b4 commit e6701b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion goodtablesio/app.py
@@ -1,4 +1,5 @@
import logging
import sqlalchemy
from flask import Flask, render_template

from goodtablesio import settings
Expand Down Expand Up @@ -46,7 +47,7 @@ def server_error(err):
return (render_template('error500.html'), 500)


@app.errorhandler(Exception)
@app.errorhandler(sqlalchemy.exc.SQLAlchemyError)
def error_handler(err):
# To prevent session from break because of unhandled error with no rollback
# https://github.com/frictionlessdata/goodtables.io/issues/97
Expand Down
3 changes: 3 additions & 0 deletions goodtablesio/blueprints/api.py
Expand Up @@ -33,6 +33,9 @@ def record_params(setup_state):

@api.app_errorhandler(Exception)
def handle_api_errors(error):
# TODO: this is not really correct way to catch blueprint errors
# because flask doesn't support error handlers per blueprint
# so this error handler is global for the whole app
if api.debug:
raise error
if not isinstance(error, APIError):
Expand Down
11 changes: 7 additions & 4 deletions goodtablesio/signals.py
@@ -1,4 +1,5 @@
import logging
import sqlalchemy
from celery import signals
from goodtablesio.utils.database import create_session
from goodtablesio.services import database
Expand All @@ -21,7 +22,9 @@ def shutdown_worker(**kwargs):

@signals.task_failure.connect
def task_failure(**kwargs):
# To prevent session from break because of unhandled error with no rollback
# https://github.com/frictionlessdata/goodtables.io/issues/97
log.info('Database session rollback by celery error handler')
database['session'].rollback()
exception = kwargs['exception']
if isinstance(exception, sqlalchemy.exc.SQLAlchemyError):
# To prevent session from break because of unhandled error with no rollback
# https://github.com/frictionlessdata/goodtables.io/issues/97
log.info('Database session rollback by celery error handler')
database['session'].rollback()

0 comments on commit e6701b9

Please sign in to comment.