Skip to content

Commit

Permalink
Fix #529 1 "This Session's transaction has been rolled back" (#530)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
LAlbertalli authored and mistercrunch committed Jun 1, 2016
1 parent b193539 commit 087c47a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions caravel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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/')
Expand Down

0 comments on commit 087c47a

Please sign in to comment.