This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new ab5c910  [bugfix] Fix Tableviz metrics column disorder (#5566)
ab5c910 is described below

commit ab5c9108017d0ce519cc518ffb04a83fb73f4ccc
Author: yamyamyuo <nicole2014f...@163.com>
AuthorDate: Thu Oct 4 23:53:26 2018 +0800

    [bugfix] Fix Tableviz metrics column disorder (#5566)
    
    * fix metrics disorder
    
    * add tableviz metric order tests
    
    * lint code
    
    * use OrderedDict to avoid metrics disorder
    
    * fix unit test
---
 superset/viz.py    |  2 ++
 tests/viz_tests.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/superset/viz.py b/superset/viz.py
index a714546..09129b7 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -100,6 +100,8 @@ class BaseViz(object):
         self.process_metrics()
 
     def process_metrics(self):
+        # metrics in TableViz is order sensitive, so metric_dict should be
+        # OrderedDict
         self.metric_dict = OrderedDict()
         fd = self.form_data
         for mkey in METRIC_KEYS:
diff --git a/tests/viz_tests.py b/tests/viz_tests.py
index c1bc15e..da7c02f 100644
--- a/tests/viz_tests.py
+++ b/tests/viz_tests.py
@@ -26,6 +26,54 @@ class BaseVizTestCase(SupersetTestCase):
         with self.assertRaises(Exception):
             viz.BaseViz(datasource, form_data)
 
+    def test_process_metrics(self):
+        # test TableViz metrics in correct order
+        form_data = {
+            'url_params': {},
+            'row_limit': 500,
+            'metric': 'sum__SP_POP_TOTL',
+            'entity': 'country_code',
+            'secondary_metric': 'sum__SP_POP_TOTL',
+            'granularity_sqla': 'year',
+            'page_length': 0,
+            'all_columns': [],
+            'viz_type': 'table',
+            'since': '2014-01-01',
+            'until': '2014-01-02',
+            'metrics': [
+                'sum__SP_POP_TOTL',
+                'SUM(SE_PRM_NENR_MA)',
+                'SUM(SP_URB_TOTL)',
+            ],
+            'country_fieldtype': 'cca3',
+            'percent_metrics': [
+                'count',
+            ],
+            'slice_id': 74,
+            'time_grain_sqla': None,
+            'order_by_cols': [],
+            'groupby': [
+                'country_name',
+            ],
+            'compare_lag': '10',
+            'limit': '25',
+            'datasource': '2__table',
+            'table_timestamp_format': '%Y-%m-%d %H:%M:%S',
+            'markup_type': 'markdown',
+            'where': '',
+            'compare_suffix': 'o10Y',
+        }
+        datasource = Mock()
+        datasource.type = 'table'
+        test_viz = viz.BaseViz(datasource, form_data)
+        expect_metric_labels = [u'sum__SP_POP_TOTL',
+                                u'SUM(SE_PRM_NENR_MA)',
+                                u'SUM(SP_URB_TOTL)',
+                                u'count',
+                                ]
+        self.assertEqual(test_viz.metric_labels, expect_metric_labels)
+        self.assertEqual(test_viz.all_metrics, expect_metric_labels)
+
     def test_get_fillna_returns_default_on_null_columns(self):
         form_data = {
             'viz_type': 'table',

Reply via email to