Skip to content

Commit

Permalink
Added check for custom filtering before using custom queries in charts
Browse files Browse the repository at this point in the history
  • Loading branch information
aschonfeld committed Sep 10, 2024
1 parent a99d8eb commit b6e3096
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
44 changes: 24 additions & 20 deletions dtale/dash_application/layout/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -1709,27 +1709,31 @@ def show_map_style(show):
),
className="row pt-3 pb-3 charts-filters",
),
html.Div(
(
html.Div(
[
html.Div(
[
query_label,
dcc.Input(
id="query-input",
type="text",
placeholder=query_placeholder,
className="form-control",
value=query_value,
style={"lineHeight": "inherit"},
),
],
className="input-group mr-3",
)
],
className="col",
),
className="row pt-3 pb-3 charts-filters",
html.Div(
[
html.Div(
[
query_label,
dcc.Input(
id="query-input",
type="text",
placeholder=query_placeholder,
className="form-control",
value=query_value,
style={"lineHeight": "inherit"},
),
],
className="input-group mr-3",
)
],
className="col",
),
className="row pt-3 pb-3 charts-filters",
)
if global_state.load_flag(inputs["data_id"], "enable_custom_filters", False)
else None
),
html.Div(
html.Div(
Expand Down
5 changes: 4 additions & 1 deletion dtale/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3380,9 +3380,12 @@ def get_chart_data(data_id):
max: maxY,
} or {error: 'Exception message', traceback: 'Exception stacktrace'}
"""
custom_query = None
if global_state.load_flag(data_id, "enable_custom_filters", False):
custom_query = get_str_arg(request, "query")
data = run_query(
handle_predefined(data_id),
build_query(data_id, get_str_arg(request, "query")),
build_query(data_id, custom_query),
global_state.get_context_variables(data_id),
)
x = get_str_arg(request, "x")
Expand Down
2 changes: 2 additions & 0 deletions tests/dtale/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,7 @@ def test_get_chart_data(unittest, rolling_data):

with app.test_client() as c:
build_data_inst({c.port: test_data})
global_state.set_app_settings(dict(enable_custom_filters=True))
response = c.get(
"/dtale/chart-data/{}".format(c.port),
query_string=dict(query="missing_col == 'blah'"),
Expand All @@ -1997,6 +1998,7 @@ def test_get_chart_data(unittest, rolling_data):
response_data["error"],
'query "security_id == 51" found no data, please alter',
)
global_state.set_app_settings(dict(enable_custom_filters=False))

df = pd.DataFrame([dict(a=i, b=np.nan) for i in range(100)])
df, _ = views.format_data(df)
Expand Down

0 comments on commit b6e3096

Please sign in to comment.