From 087c47a37e45bb9c2608bbb2279188b59547e449 Mon Sep 17 00:00:00 2001 From: Luca Albertalli Date: Tue, 31 May 2016 21:16:32 -0700 Subject: [PATCH] Fix #529 1 "This Session's transaction has been rolled back" (#530) * Fixing the specific issue * Added an additional fix for a similar error in #529 Background: - When an object is modified by SQLAlchemy, it is invalidated so need to be fetched again from the DB - If there's an exception during a transaction, SQLAlchemy performs a rollback and mark the connection as dirty. Bug: - When handling exceptions, the exception handler tries to access the name of the cluster in the main object. Since the name has been invalidated due to a write, SQLAlchemy tries to fetch it on a 'dirty' connection and spits out an error. Solution: - Fetch the information for handling the exception before starting the process. --- caravel/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/caravel/views.py b/caravel/views.py index b52abfda99e6..b3bb3b4ec76a 100644 --- a/caravel/views.py +++ b/caravel/views.py @@ -317,13 +317,14 @@ class TableModelView(CaravelModelView, DeleteMixin): # noqa } def post_add(self, table): + table_name = table.table_name try: table.fetch_metadata() except Exception as e: logging.exception(e) flash( "Table [{}] doesn't seem to exist, " - "couldn't fetch metadata".format(table.table_name), + "couldn't fetch metadata".format(table_name), "danger") utils.merge_perm(sm, 'datasource_access', table.perm) @@ -1001,12 +1002,13 @@ def refresh_datasources(self): """endpoint that refreshes druid datasources metadata""" session = db.session() for cluster in session.query(models.DruidCluster).all(): + cluster_name = cluster.cluster_name try: cluster.refresh_datasources() except Exception as e: flash( "Error while processing cluster '{}'\n{}".format( - cluster, str(e)), + cluster_name, str(e)), "danger") logging.exception(e) return redirect('/druidclustermodelview/list/')