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: avoid escaping bind-like params containing colons #17419

Merged
merged 3 commits into from
Nov 13, 2021

Conversation

villebro
Copy link
Member

@villebro villebro commented Nov 12, 2021

SUMMARY

A recent PR #17111 that fixed 500s being returned when a virtual table query contained a word prefixed by a colon (e.g. ":foo") caused a regression that unnecessarily also escaped similar strings that contained/ended in a colon (e.g. ":foo:" or ":foo:bar").

This PR simplifies the escaping logic by simply escaping all colons with a backslash when sa.text is used, as these elements are never expected to contain binds. In addition, an integration test is added that contains colons in the virtual table query, metric, filter and where clauses. The new test fails on current master with a 500.

AFTER

Now all strings including colons are displayed properly on the query:
image

BEFORE

Before the virtual table was incorrectly escaped in multiple places:
image

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@villebro villebro changed the title fix: avoid escaping bind-like params ending in colon fix: avoid escaping bind-like params containing colons Nov 12, 2021
@villebro villebro added the v1.4 label Nov 12, 2021
@codecov
Copy link

codecov bot commented Nov 12, 2021

Codecov Report

Merging #17419 (65acf8a) into master (ffa55f7) will decrease coverage by 0.18%.
The diff coverage is 94.11%.

❗ Current head 65acf8a differs from pull request most recent head 5c1cf7f. Consider uploading reports for the commit 5c1cf7f to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17419      +/-   ##
==========================================
- Coverage   77.01%   76.83%   -0.19%     
==========================================
  Files        1040     1041       +1     
  Lines       56077    56057      -20     
  Branches     7738     7738              
==========================================
- Hits        43190    43069     -121     
- Misses      12629    12730     +101     
  Partials      258      258              
Flag Coverage Δ
hive ?
mysql 81.94% <94.11%> (+0.05%) ⬆️
postgres 81.95% <94.11%> (+0.05%) ⬆️
presto ?
python 82.04% <94.11%> (-0.36%) ⬇️
sqlite 81.63% <94.11%> (+0.05%) ⬆️

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

Impacted Files Coverage Δ
...frontend/src/dashboard/components/Header/index.jsx 68.85% <ø> (ø)
...teFilterControl/components/DateFunctionTooltip.tsx 100.00% <ø> (ø)
superset/charts/commands/data.py 97.95% <ø> (+1.59%) ⬆️
superset/utils/core.py 89.86% <ø> (-0.25%) ⬇️
superset/connectors/sqla/models.py 86.60% <83.33%> (-1.38%) ⬇️
superset/charts/data/query_context_cache_loader.py 90.00% <90.00%> (ø)
superset/charts/api.py 85.22% <100.00%> (+4.17%) ⬆️
superset/charts/data/api.py 88.48% <100.00%> (+0.25%) ⬆️
superset/utils/date_parser.py 96.63% <100.00%> (+0.04%) ⬆️
superset/db_engines/hive.py 0.00% <0.00%> (-85.19%) ⬇️
... and 9 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 ffa55f7...5c1cf7f. Read the comment docs.

Copy link
Member

@john-bodley john-bodley left a comment

Choose a reason for hiding this comment

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

LGTM, with one non-blocking comment. Its somewhat strange that we need to handle this logic, i.e., blindly I would have assumed that SQLAlchemy would deal with the escaping.

superset/connectors/sqla/models.py Outdated Show resolved Hide resolved
tests/integration_tests/charts/api_tests.py Outdated Show resolved Hide resolved
@villebro
Copy link
Member Author

Thanks for the review @john-bodley, good comments to my oversights!

LGTM, with one non-blocking comment. Its somewhat strange that we need to handle this logic, i.e., blindly I would have assumed that SQLAlchemy would deal with the escaping.

AFAIK, currently there is no way of indicating that the clause is literal (like literal_column, for instance). Hence colons need to be escaped to indicate to SQLAlchemy that they should not be made available as bind parameters during compilation. But I'm going to propose adding is_literal to the text() factory, and then adding a literal_text factory as shorthand to match (literal_column), as I've seen multiple other people ask for the same thing elsewhere (in all the posts I've found, the author of SQLAlchemy always recommends just escaping the bind-like parameters).

@villebro villebro merged commit ad8a7c4 into apache:master Nov 13, 2021
@villebro villebro deleted the villebro/escape-bind-pt2 branch November 13, 2021 07:09
eschutho pushed a commit that referenced this pull request Dec 6, 2021
* fix: avoid escaping bind-like params containing colons

* fix query for mysql

* address comments

(cherry picked from commit ad8a7c4)
AAfghahi pushed a commit that referenced this pull request Jan 10, 2022
* fix: avoid escaping bind-like params containing colons

* fix query for mysql

* address comments
@mistercrunch mistercrunch added 🍒 1.4.0 🍒 1.4.1 🍒 1.4.2 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.5.0 labels Mar 13, 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 preset-io size/L v1.4 🍒 1.4.0 🍒 1.4.1 🍒 1.4.2 🚢 1.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants