Skip to content

Commit

Permalink
[bugfix] 'DruidCluster' object has no attribute 'db_engine_spec' (apa…
Browse files Browse the repository at this point in the history
…che#5765)

* [bugfix] 'DruidCluster' object has no attribute 'db_engine_spec'

* Fix tests

(cherry picked from commit 135539c)
  • Loading branch information
mistercrunch authored and betodealmeida committed Oct 30, 2018
1 parent 47c05ff commit ad6541b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 60 deletions.
9 changes: 7 additions & 2 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ def process_metrics(self):
def get_metric_label(self, metric):
if isinstance(metric, string_types):
return metric

if isinstance(metric, dict):
return self.datasource.database.db_engine_spec.mutate_expression_label(
metric.get('label'))
metric = metric.get('label')

if self.datasource.type == 'table':
db_engine_spec = self.datasource.database.db_engine_spec
metric = db_engine_spec.mutate_expression_label(metric)
return metric

@staticmethod
def handle_js_int_overflow(data):
Expand Down
19 changes: 19 additions & 0 deletions tests/base_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import unittest

from flask_appbuilder.security.sqla import models as ab_models
from mock import Mock
import pandas as pd

from superset import app, cli, db, security_manager, utils
from superset.connectors.druid.models import DruidCluster, DruidDatasource
Expand Down Expand Up @@ -147,6 +149,23 @@ def get_druid_ds_by_name(self, name):
return db.session.query(DruidDatasource).filter_by(
datasource_name=name).first()

def get_datasource_mock(self):
datasource = Mock()
results = Mock()
results.query = Mock()
results.status = Mock()
results.error_message = None
results.df = pd.DataFrame()
datasource.type = 'table'
datasource.query = Mock(return_value=results)
mock_dttm_col = Mock()
datasource.get_col = Mock(return_value=mock_dttm_col)
datasource.query = Mock(return_value=results)
datasource.database = Mock()
datasource.database.db_engine_spec = Mock()
datasource.database.db_engine_spec.mutate_expression_label = lambda x: x
return datasource

def get_resp(
self, url, data=None, follow_redirects=True, raise_on_error=True):
"""Shortcut to get the parsed results while following redirects"""
Expand Down
Loading

0 comments on commit ad6541b

Please sign in to comment.