You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "eschutho (via GitHub)" <gi...@apache.org> on 2026/08/24 16:42:16 UTC

[PR] fix(explore): catch TemplateError when validating access for query-backed form_data [superset]

eschutho opened a new pull request, #43470:
URL: https://github.com/apache/superset/pull/43470

   ### SUMMARY
   `ExploreFormDataRestApi` (the cache backing chart Explore / Drill-by state) lets a client reference a SQL Lab query as the chart's datasource (`datasource_type=query`). Access to that datasource is validated via `superset.explore.utils.check_query_access`, which calls `security_manager.raise_for_access(query=query)`. When the query hasn't been executed yet (or was edited after last execution), that call falls back to Jinja-rendering the query's raw SQL (`process_jinja_sql`) to resolve the tables it references — the exact same rendering step already known to raise `jinja2.exceptions.TemplateError` for malformed templates (see #42366, #42401, and the more recent #43423/#43433 in the tag-access-check family).
   
   Unlike those command-layer call sites, this one had no `except TemplateError` at all, so the raw jinja2 exception propagated straight through `CreateFormDataCommand`/`GetFormDataCommand`/`UpdateFormDataCommand`/`DeleteFormDataCommand` (none of which catch anything but `SQLAlchemyError`) up to `ExploreFormDataRestApi`, landing as an opaque, unclassified 500 from all four `POST`/`PUT`/`GET`/`DELETE /api/v1/explore/form_data` handlers.
   
   ### PROBLEM
   A user-controlled input (a saved SQL Lab query with malformed Jinja templating, referenced as a chart's datasource) can trigger a raw `jinja2.exceptions.TemplateError` that surfaces as an unclassified 500, instead of a proper 4xx `SupersetException`.
   
   ### FIX
   - `superset/explore/utils.py::check_query_access` now catches `TemplateError` around the `raise_for_access(query=query)` call and re-raises it as `SupersetTemplateException` (existing, 422 — no new exception class needed), preserving the original message.
   - `superset/explore/form_data/api.py` maps `SupersetTemplateException` to a proper `ex.status` response in all four `ExploreFormDataRestApi` handlers, mirroring the existing `except SupersetTemplateException as ex: return self.response(ex.status, message=str(ex))` idiom already used in `superset/datasets/api.py`.
   
   No behavior change for any other exception type or datasource type.
   
   ### TESTING INSTRUCTIONS
   - New unit test `tests/unit_tests/explore/utils_test.py::test_query_malformed_jinja_template`: mocks `raise_for_access` to raise `jinja2.exceptions.TemplateSyntaxError` and asserts `check_datasource_access` now raises `SupersetTemplateException` instead. Verified this test fails on pre-fix code (raw `TemplateSyntaxError` propagates) and passes post-fix.
   - `ruff check` / `ruff format --check` clean on all changed files.
   - Full `tests/unit_tests/explore/` and `tests/unit_tests/commands/explore/` suites pass (24 tests).
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(explore): catch TemplateError when validating access for query-backed form_data [superset]

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho merged PR #43470:
URL: https://github.com/apache/superset/pull/43470


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(explore): catch TemplateError when validating access for query-backed form_data [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43470:
URL: https://github.com/apache/superset/pull/43470#issuecomment-5398366107

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(explore): catch TemplateError when validating access for query-backed form_data [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43470:
URL: https://github.com/apache/superset/pull/43470#issuecomment-5456253271

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
   
   <details>
   <summary>
   Bito Usage Guide
   </summary>
   
   **Commands**
         
   Type the following command in the pull request comment and save the comment.
         
   - `/review` - Manually triggers an incremental AI Review.
   - `/review full` - Manually triggers a full AI Review.
   
   - `/pause` - Pauses automatic reviews on this pull request.
   - `/resume` - Resumes automatic reviews.
   - `/resolve` - Marks all Bito-posted review comments as resolved.
   - `/abort` - Cancels all in-progress reviews.
   
         
   Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
         
   **Configuration**
   
   This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
         
   **Documentation & Help**
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
   
   </details>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(explore): catch TemplateError when validating access for query-backed form_data [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #43470:
URL: https://github.com/apache/superset/pull/43470#issuecomment-5454577851

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/43470?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `33.33333%` with `10 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 66.20%. Comparing base ([`abf338d`](https://app.codecov.io/gh/apache/superset/commit/abf338d611de6bb2ea83890cf2e1481e145d7b16?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`ab68c19`](https://app.codecov.io/gh/apache/superset/commit/ab68c193358ba48fd7053e1ad49355795dbb09d5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/43470?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [superset/explore/form\_data/api.py](https://app.codecov.io/gh/apache/superset/pull/43470?src=pr&el=tree&filepath=superset%2Fexplore%2Fform_data%2Fapi.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvZXhwbG9yZS9mb3JtX2RhdGEvYXBpLnB5) | 11.11% | [8 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/43470?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/explore/utils.py](https://app.codecov.io/gh/apache/superset/pull/43470?src=pr&el=tree&filepath=superset%2Fexplore%2Futils.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvZXhwbG9yZS91dGlscy5weQ==) | 66.66% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/43470?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   > :exclamation:  There is a different number of reports uploaded between BASE (abf338d) and HEAD (ab68c19). Click for more details.
   > 
   > <details><summary>HEAD has 23 uploads less than BASE</summary>
   >
   >| Flag | BASE (abf338d) | HEAD (ab68c19) |
   >|------|------|------|
   >|python|20|3|
   >|presto|3|1|
   >|hive|3|1|
   >|sqlite|3|1|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff             @@
   ##           master   #43470       +/-   ##
   ===========================================
   - Coverage   79.21%   66.20%   -13.01%     
   ===========================================
     Files        2879     2879               
     Lines      165922   165936       +14     
     Branches    38377    38377               
   ===========================================
   - Hits       131427   109855    -21572     
   - Misses      32018    53851    +21833     
   + Partials     2477     2230      -247     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/43470/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [hive](https://app.codecov.io/gh/apache/superset/pull/43470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `37.93% <20.00%> (-0.01%)` | :arrow_down: |
   | [mysql](https://app.codecov.io/gh/apache/superset/pull/43470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [postgres](https://app.codecov.io/gh/apache/superset/pull/43470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [presto](https://app.codecov.io/gh/apache/superset/pull/43470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.84% <20.00%> (-0.01%)` | :arrow_down: |
   | [python](https://app.codecov.io/gh/apache/superset/pull/43470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.53% <33.33%> (-26.23%)` | :arrow_down: |
   | [sqlite](https://app.codecov.io/gh/apache/superset/pull/43470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.39% <33.33%> (-0.01%)` | :arrow_down: |
   | [unit](https://app.codecov.io/gh/apache/superset/pull/43470/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/43470?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org