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(sqla): use same template processor in all methods #22280

Merged
merged 5 commits into from
Dec 3, 2022

Conversation

villebro
Copy link
Member

@villebro villebro commented Nov 30, 2022

SUMMARY

Some methods in the SQLA model weren't using the already instantiated template processor, making the following template kwargs unavailable to certain fields, namely calculated expressions and saved metrics:

template_kwargs = {
"columns": columns,
"from_dttm": from_dttm.isoformat() if from_dttm else None,
"groupby": groupby,
"metrics": metrics,
"row_limit": row_limit,
"row_offset": row_offset,
"time_column": granularity,
"time_grain": time_grain,
"to_dttm": to_dttm.isoformat() if to_dttm else None,
"table_columns": [col.column_name for col in self.columns],
"filter": filter,
}

This fixes the issue and adds tests for all relevant cases:

  • Jinja in virtual table query
  • Jinja in saved metric
  • Jinja in calculated column
  • Jinja in adhoc column
  • Jinja in adhoc metric

AFTER

Notice how the metric referencing the time grain is now rendered correctly:
image

BEFORE

Previously it didn't render, as the time_grain variable wasn't available to the saved metric:
image

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue: closes: Templates are not being rendered in dataset metrics #22261
  • 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

@codecov
Copy link

codecov bot commented Nov 30, 2022

Codecov Report

Merging #22280 (75ba34d) into master (b1f8fd4) will decrease coverage by 1.30%.
The diff coverage is 61.40%.

❗ Current head 75ba34d differs from pull request most recent head 82478e2. Consider uploading reports for the commit 82478e2 to get more accurate results

@@            Coverage Diff             @@
##           master   #22280      +/-   ##
==========================================
- Coverage   66.74%   65.43%   -1.31%     
==========================================
  Files        1841     1846       +5     
  Lines       70219    70290      +71     
  Branches     7671     7683      +12     
==========================================
- Hits        46865    45994     -871     
- Misses      21371    22304     +933     
- Partials     1983     1992       +9     
Flag Coverage Δ
mysql 78.05% <71.64%> (-0.03%) ⬇️
postgres 78.11% <71.64%> (-0.03%) ⬇️
presto ?
python 78.24% <71.64%> (-2.90%) ⬇️
sqlite 76.57% <71.64%> (-0.03%) ⬇️
unit ?

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

Impacted Files Coverage Δ
.../components/Chart/DrillDetail/DrillDetailModal.tsx 92.30% <ø> (ø)
...nts/Chart/DrillDetail/DrillDetailTableControls.tsx 94.11% <ø> (ø)
...ts/Table/header-renderers/HeaderWithRadioGroup.tsx 0.00% <0.00%> (ø)
superset/views/database/views.py 31.27% <36.00%> (-0.09%) ⬇️
superset-frontend/src/components/Table/index.tsx 70.23% <40.00%> (+7.08%) ⬆️
...c/components/Chart/DrillDetail/DrillDetailPane.tsx 76.04% <47.61%> (-6.68%) ⬇️
superset/connectors/sqla/models.py 88.56% <90.62%> (-0.56%) ⬇️
...set-frontend/src/components/Table/VirtualTable.tsx 73.43% <100.00%> (+65.62%) ⬆️
...ponents/Table/cell-renderers/BooleanCell/index.tsx 100.00% <100.00%> (ø)
...components/Table/cell-renderers/NullCell/index.tsx 100.00% <100.00%> (ø)
... and 72 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@pull-request-size pull-request-size bot added size/L and removed size/M labels Nov 30, 2022
@mayurnewase
Copy link
Contributor

mayurnewase commented Dec 2, 2022

Code looks good to me, tested manually with dataset's calculated column + metric and chart adhoc metric works as expected.
Screenshot from 2022-12-03 02-29-47

@villebro villebro merged commit 1ad5147 into apache:master Dec 3, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.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 size/L 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Templates are not being rendered in dataset metrics
4 participants