Skip to content

Commit

Permalink
Merge pull request apache#25 from michellethomas/fix_extra_queries
Browse files Browse the repository at this point in the history
Move run_extra_queries outsize of BaseViz init
  • Loading branch information
michellethomas authored Mar 17, 2018
2 parents e64662f + ffd2de3 commit 55e20ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ ignored-modules=numpy,pandas,alembic.op,sqlalchemy,alembic.context,flask_appbuil
# List of class names for which member attributes should not be checked (useful
# for classes with dynamically set attributes). This supports the use of
# qualified names.
ignored-classes=optparse.Values,thread._local,_thread._local
ignored-classes=optparse.Values,thread._local,_thread._local,sqlalchemy.orm.scoping.scoped_session

# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
Expand Down
11 changes: 5 additions & 6 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def __init__(self, datasource, form_data, force=False):
self._some_from_cache = False
self._any_cache_key = None
self._any_cached_dttm = None

self.run_extra_queries()
self._extra_chart_data = None

def run_extra_queries(self):
"""Lyfecycle method to use when more than one query is needed
Expand Down Expand Up @@ -285,6 +284,7 @@ def cache_key(self, query_obj):

def get_payload(self, query_obj=None):
"""Returns a payload of metadata and data"""
self.run_extra_queries()
payload = self.get_df_payload(query_obj)

df = payload.get('df')
Expand Down Expand Up @@ -1118,7 +1118,6 @@ def process_data(self, df, aggregate=False):
def run_extra_queries(self):
fd = self.form_data
time_compare = fd.get('time_compare')
self.extra_chart_data = None
if time_compare:
query_object = self.query_obj()
delta = utils.parse_human_timedelta(time_compare)
Expand All @@ -1136,15 +1135,15 @@ def run_extra_queries(self):
if df2 is not None:
df2[DTTM_ALIAS] += delta
df2 = self.process_data(df2)
self.extra_chart_data = self.to_series(
self._extra_chart_data = self.to_series(
df2, classed='superset', title_suffix='---')

def get_data(self, df):
df = self.process_data(df)
chart_data = self.to_series(df)

if self.extra_chart_data:
chart_data += self.extra_chart_data
if self._extra_chart_data:
chart_data += self._extra_chart_data
chart_data = sorted(chart_data, key=lambda x: x['key'])

return chart_data
Expand Down

0 comments on commit 55e20ae

Please sign in to comment.