Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show missing parameters in query #12049

Merged
merged 5 commits into from
Dec 16, 2020
Merged

Conversation

betodealmeida
Copy link
Member

SUMMARY

This PR makes SQL Lab discriminate errors that happen because of missing parameters in the query, showing them as "Parameter Error" instead of "Database Error".

The error component in SQL Lab seems to be outdated, but I didn't want to change it now since we would like to include this fix before 1.0. Since I'm using SIP-40 for the error in the backend, hopefully we can migrate SQL Lab to use something like <DatabaseErrorMessage /> and it will Just Work™.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Screenshot_2020-12-14 Superset

TEST PLAN

Tested manually (see screenshot) and also added a unit test.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

}}
code={qe.templateParams}
/>
{isFeatureEnabled(FeatureFlag.ENABLE_TEMPLATE_PROCESSING) && (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are showing "Parameters" in SQL Lab even though the functionality is now behind a feature flag in the backend. I turned it off here if the functionality is not enabled.

cc: @hughhhh

@codecov-io
Copy link

codecov-io commented Dec 15, 2020

Codecov Report

Merging #12049 (29e27eb) into master (3d56f58) will decrease coverage by 3.09%.
The diff coverage is 84.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12049      +/-   ##
==========================================
- Coverage   66.58%   63.48%   -3.10%     
==========================================
  Files         952      957       +5     
  Lines       46703    47010     +307     
  Branches     4578     4594      +16     
==========================================
- Hits        31096    29845    -1251     
- Misses      15458    16980    +1522     
- Partials      149      185      +36     
Flag Coverage Δ
cypress ?
javascript 62.54% <55.55%> (-0.16%) ⬇️
python 64.05% <100.00%> (-0.54%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rset-frontend/src/components/ErrorMessage/types.ts 100.00% <ø> (ø)
...erset-frontend/src/SqlLab/components/SqlEditor.jsx 49.41% <25.00%> (-2.35%) ⬇️
...erset-frontend/src/SqlLab/components/ResultSet.tsx 66.97% <75.00%> (+0.15%) ⬆️
superset-frontend/src/featureFlags.ts 87.50% <100.00%> (-12.50%) ⬇️
superset/errors.py 100.00% <100.00%> (ø)
superset/jinja_context.py 87.57% <100.00%> (+0.07%) ⬆️
superset/utils/core.py 89.26% <100.00%> (+0.04%) ⬆️
superset/views/core.py 72.93% <100.00%> (-2.30%) ⬇️
superset-frontend/src/SqlLab/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/explore/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
... and 188 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d56f58...29e27eb. Read the comment docs.

superset/views/core.py Outdated Show resolved Hide resolved
Copy link
Member

@eschutho eschutho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit on the error string duplication, but lgtm

superset/utils/core.py Outdated Show resolved Hide resolved
@betodealmeida betodealmeida merged commit 8bda6b0 into apache:master Dec 16, 2020
Comment on lines +2519 to +2520
ast = template_processor._env.parse(rendered_query)
undefined = find_undeclared_variables(ast) # type: ignore
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robdiciuccio want to confirm that this is ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not guaranteed that the template processor with be Jinja-based, due to how CUSTOM_TEMPLATE_PROCESSORS operates. I suggest checking that template_processor is an instance of JinjaTemplateProcessor here instead of checking ENABLE_TEMPLATE_PROCESSING.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that, I don't see any security issues with using find_undeclared_variables in this context. I'm assuming that undefined variables don't raise an error during process_template?

@@ -296,7 +297,7 @@ def __init__(
self._schema = table.schema
self._extra_cache_keys = extra_cache_keys
self._context: Dict[str, Any] = {}
self._env = SandboxedEnvironment()
self._env = SandboxedEnvironment(undefined=DebugUndefined)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is DebugUndefined required to make find_undeclared_variables function? Doesn't seem to be a requirement in the docs.

@@ -2506,6 +2514,28 @@ def sql_json_exec( # pylint: disable=too-many-statements,too-many-locals
f"Query {query_id}: Template syntax error: {error_msg}"
)

# pylint: disable=protected-access
if is_feature_enabled("ENABLE_TEMPLATE_PROCESSING"):
ast = template_processor._env.parse(rendered_query)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: accessing a private property from outside the class

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.0.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 1.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants