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

[fix] Adding check for invalid filter columns #7888

Merged

Conversation

john-bodley
Copy link
Member

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

This PR fixes an issue where if you specified an invalid column (achievable in the URL) in a simple filter, i.e., not custom SQL, then the filter was simply ignored and the the query would execute sans the filter with no clear indication to the user that the filter wasn't being applied.

This PR applies the same logic as invalid metrics and raises an exception if the column is invalid. Note I added unit tests to cover both the invalid metric and column use cases.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

BEFORE

Screen Shot 2019-07-17 at 3 32 12 PM

AFTER

Screen Shot 2019-07-17 at 3 29 58 PM

TEST PLAN

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

REVIEWERS

to: @michellethomas @mistercrunch @williaster

elif op == "IS NOT NULL":
where_clause_and.append(col_obj.get_sqla_col() != None) # noqa
col_obj = cols[col]
is_list_target = op in ("in", "not in")
Copy link
Member Author

Choose a reason for hiding this comment

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

Note this block is just dedented as the if col_obj check is not required given the addition of the new check.

Copy link
Contributor

@williaster williaster left a comment

Choose a reason for hiding this comment

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

Thanks for looking at this and adding tests, I think this is a pretty important check for "data correctness" 💯

Had a couple small suggestions re the error messages.

@@ -721,43 +721,46 @@ def get_sqla_query( # sqla
if not all([flt.get(s) for s in ["col", "op"]]):
continue
col = flt["col"]

if col not in cols:
raise Exception(_(f"Column '{col}' is not valid"))
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we could update the language to be a little more precise here? For example Column '{col}' does not exist / ... not found?

Copy link
Member Author

@john-bodley john-bodley Jul 17, 2019

Choose a reason for hiding this comment

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

@williaster I think the wording here can be difficult as it's in reference to Superset's data model as opposed to the schema of the underlying table. I think "does not exist" is more precise/clearer than "is not valid" though.

@@ -649,7 +649,7 @@ def get_sqla_query( # sqla
elif m in metrics_dict:
metrics_exprs.append(metrics_dict.get(m).get_sqla_col())
else:
raise Exception(_("Metric '{}' is not valid".format(m)))
raise Exception(_(f"Metric '{m}' is not valid"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto re the error message here? Metric '{m}' does not exist / ... not found?

@codecov-io
Copy link

codecov-io commented Jul 17, 2019

Codecov Report

Merging #7888 into master will increase coverage by <.01%.
The diff coverage is 36.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7888      +/-   ##
==========================================
+ Coverage   65.78%   65.79%   +<.01%     
==========================================
  Files         461      461              
  Lines       22187    22188       +1     
  Branches     2425     2425              
==========================================
+ Hits        14596    14598       +2     
+ Misses       7470     7469       -1     
  Partials      121      121
Impacted Files Coverage Δ
superset/connectors/sqla/models.py 82.67% <36.36%> (+0.2%) ⬆️

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 174a48a...06d26bd. Read the comment docs.

@john-bodley john-bodley force-pushed the john-bodley--fix-invalid-column branch 2 times, most recently from 651d674 to 17c2907 Compare July 17, 2019 23:12
@john-bodley
Copy link
Member Author

@williaster I addressed your comments.

@@ -649,7 +649,7 @@ def get_sqla_query( # sqla
elif m in metrics_dict:
metrics_exprs.append(metrics_dict.get(m).get_sqla_col())
else:
raise Exception(_("Metric '{}' is not valid".format(m)))
raise Exception(_(f"Metric '{m}' does not exist"))
Copy link
Member

Choose a reason for hiding this comment

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

It was wrong before, but variable formatting with get_text should use a different formatting scheme. Should look something like _("Metric '%(metric)s' does not exist", metric=metric)
https://pythonhosted.org/Flask-Babel/#flask.ext.babel.gettext

raise Exception(
_("Metric '{}' is not valid".format(timeseries_limit_metric))
)
raise Exception(_(f"Metric '{timeseries_limit_metric}' does not exist"))
Copy link
Member

Choose a reason for hiding this comment

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

Same as above...

@john-bodley john-bodley changed the title [sqla] Adding check for invalid filter columns [fix] Adding check for invalid filter columns Jul 18, 2019
@john-bodley john-bodley force-pushed the john-bodley--fix-invalid-column branch from 17c2907 to 06d26bd Compare July 18, 2019 15:18
@john-bodley
Copy link
Member Author

@mistercrunch I addressed your comments.

@john-bodley john-bodley merged commit 2b3e7fe into apache:master Jul 18, 2019
@john-bodley john-bodley deleted the john-bodley--fix-invalid-column branch July 18, 2019 15:51
john-bodley pushed a commit to john-bodley/superset that referenced this pull request Jul 18, 2019
john-bodley added a commit to airbnb/superset-fork that referenced this pull request Jul 18, 2019
@john-bodley john-bodley mentioned this pull request Jul 26, 2019
12 tasks
alex-mark pushed a commit to alex-mark/incubator-superset that referenced this pull request Jul 29, 2019
john-bodley pushed a commit to john-bodley/superset that referenced this pull request Jul 29, 2019
john-bodley added a commit that referenced this pull request Jul 29, 2019
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0 labels Feb 28, 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 🚢 0.34.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants