From 04d769ff249e8c9e616133dc17639088438667cb Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Fri, 15 Apr 2016 15:00:49 -0700 Subject: [PATCH] Some more error handling when rendering the explore view (#361) --- caravel/forms.py | 4 +++- caravel/views.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/caravel/forms.py b/caravel/forms.py index ec8d65d1074c6..0094ef4e67834 100644 --- a/caravel/forms.py +++ b/caravel/forms.py @@ -112,11 +112,13 @@ def __init__(self, viz): from caravel.viz import viz_types viz = self.viz datasource = viz.datasource + if not datasource.metrics_combo: + raise Exception("Please define at least one metric for your table") default_metric = datasource.metrics_combo[0][0] gb_cols = datasource.groupby_column_names default_groupby = gb_cols[0] if gb_cols else None - group_by_choices = [(s, s) for s in datasource.groupby_column_names] + group_by_choices = self.choicify(gb_cols) # Pool of all the fields that can be used in Caravel self.field_dict = { 'viz_type': SelectField( diff --git a/caravel/views.py b/caravel/views.py index b8d745bd283bf..b34d1e2507b2b 100644 --- a/caravel/views.py +++ b/caravel/views.py @@ -490,10 +490,14 @@ def explore(self, datasource_type, datasource_id): return redirect(datasource.default_endpoint) if not viz_type: viz_type = "table" - obj = viz.viz_types[viz_type]( - datasource, - form_data=request.args, - slice_=slc) + try: + obj = viz.viz_types[viz_type]( + datasource, + form_data=request.args, + slice_=slc) + except Exception as e: + flash(str(e), "danger") + return redirect(error_redirect) if request.args.get("json") == "true": status = 200 try: