from sqlalchemy.exc import SQLAlchemyError
from action import scanner
from helpers import make_config, make_session, make_redis


config = make_config()
sess = make_session(None, config)
redis = make_redis(config)
scanner = scanner.Scanner(config, sess, redis)


def run_task(task_name, *args, **kwargs):

    method = getattr(scanner, task_name)
    try:
        method(*args, **kwargs)
    except SQLAlchemyError as e:
        sess.rollback()
    else:
        sess.commit()
    finally:
        sess.close()

from sqlalchemy.exc import SQLAlchemyError
from action import scanner
from helpers import make_config, make_session, make_redis


config = make_config()
sess = make_session(None, config)
redis = make_redis(config)
scanner = scanner.Scanner(config, sess, redis)


def run_task(task_name, *args, **kwargs):

    method = getattr(scanner, task_name)
    try:
        method(*args, **kwargs)
    except SQLAlchemyError as e:
        sess.rollback()
        raise
    else:
        sess.commit()
    finally:
        sess.close()

Print SQLAlchemy exceptions to stdout and reraise
Print SQLAlchemy exceptions to stdout and reraise

  from sqlalchemy.exc import SQLAlchemyError
  from action import scanner
  from helpers import make_config, make_session, make_redis
  
  
  config = make_config()
  sess = make_session(None, config)
  redis = make_redis(config)
  scanner = scanner.Scanner(config, sess, redis)
  
  
  def run_task(task_name, *args, **kwargs):
  
      method = getattr(scanner, task_name)
      try:
          method(*args, **kwargs)
      except SQLAlchemyError as e:
          sess.rollback()
+         raise
      else:
          sess.commit()
      finally:
          sess.close()
  
Print SQLAlchemy exceptions to stdout and reraise
## Code Before:
from sqlalchemy.exc import SQLAlchemyError
from action import scanner
from helpers import make_config, make_session, make_redis


config = make_config()
sess = make_session(None, config)
redis = make_redis(config)
scanner = scanner.Scanner(config, sess, redis)


def run_task(task_name, *args, **kwargs):

    method = getattr(scanner, task_name)
    try:
        method(*args, **kwargs)
    except SQLAlchemyError as e:
        sess.rollback()
    else:
        sess.commit()
    finally:
        sess.close()

## Instruction:
Print SQLAlchemy exceptions to stdout and reraise
## Code After:
from sqlalchemy.exc import SQLAlchemyError
from action import scanner
from helpers import make_config, make_session, make_redis


config = make_config()
sess = make_session(None, config)
redis = make_redis(config)
scanner = scanner.Scanner(config, sess, redis)


def run_task(task_name, *args, **kwargs):

    method = getattr(scanner, task_name)
    try:
        method(*args, **kwargs)
    except SQLAlchemyError as e:
        sess.rollback()
        raise
    else:
        sess.commit()
    finally:
        sess.close()
