You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "john-bodley (via GitHub)" <gi...@apache.org> on 2024/03/25 21:47:11 UTC
[PR] fix: Provide more inclusive error handling for saved queries [superset]
john-bodley opened a new pull request, #27644:
URL: https://github.com/apache/superset/pull/27644
<!---
Please write the PR title following the conventions at https://www.conventionalcommits.org/en/v1.0.0/
Example:
fix(dashboard): load charts correctly
-->
### SUMMARY
When extracting a user's Saved Queries there maybe an issue rendering the the Jinja template, i.e., fields maybe undefined. This PR ensures that the `SqlTablesMixin.sql_tables` method additionally captures any Jinja templating errors.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
<!--- Skip this if not applicable -->
### TESTING INSTRUCTIONS
CI.
### ADDITIONAL INFORMATION
<!--- Check any relevant boxes with "x" -->
<!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] 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
--
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: Provide more inclusive error handling for saved queries [superset]
Posted by "john-bodley (via GitHub)" <gi...@apache.org>.
john-bodley commented on code in PR #27644:
URL: https://github.com/apache/superset/pull/27644#discussion_r1539766395
##########
superset/models/sql_lab.py:
##########
@@ -76,7 +77,7 @@ def sql_tables(self) -> list[Table]:
self.database.db_engine_spec.engine, # type: ignore
)
)
- except SupersetSecurityException:
+ except (SupersetSecurityException, TemplateError):
Review Comment:
@michael-s-molina per a code search the [caller](https://github.com/apache/superset/blob/ce210eebdeeb374611e5b273379a889244f64288/superset/queries/saved_queries/api.py#L100) is the Flask-AppBuilder API and AFAIK that logic is all somewhat magical, i.e., I'm not sure if/how errors are handled. Given that, this was the highest point in the stack where I felt the error should be handled.
--
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: Provide more inclusive error handling for saved queries [superset]
Posted by "john-bodley (via GitHub)" <gi...@apache.org>.
john-bodley commented on code in PR #27644:
URL: https://github.com/apache/superset/pull/27644#discussion_r1539766395
##########
superset/models/sql_lab.py:
##########
@@ -76,7 +77,7 @@ def sql_tables(self) -> list[Table]:
self.database.db_engine_spec.engine, # type: ignore
)
)
- except SupersetSecurityException:
+ except (SupersetSecurityException, TemplateError):
Review Comment:
@michael-s-molina per a code search the [caller](https://github.com/apache/superset/blob/ce210eebdeeb374611e5b273379a889244f64288/superset/queries/saved_queries/api.py#L100) is the Flask-AppBuilder API and AFAIK that logic is all somewhat magical, i.e., I'm not sure if/how error handling is dealt with. This was the highest point in the stack where I felt the error should be handled.
--
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: Provide more inclusive error handling for saved queries [superset]
Posted by "john-bodley (via GitHub)" <gi...@apache.org>.
john-bodley commented on code in PR #27644:
URL: https://github.com/apache/superset/pull/27644#discussion_r1539766395
##########
superset/models/sql_lab.py:
##########
@@ -76,7 +77,7 @@ def sql_tables(self) -> list[Table]:
self.database.db_engine_spec.engine, # type: ignore
)
)
- except SupersetSecurityException:
+ except (SupersetSecurityException, TemplateError):
Review Comment:
@michael-s-molina per a code search the [caller](https://github.com/apache/superset/blob/ce210eebdeeb374611e5b273379a889244f64288/superset/queries/saved_queries/api.py#L100) is the Flask-AppBuilder API and AFAIK that logic is all somewhat magical, i.e., I'm not sure if/how model errors are handled and it seems like the various API endpoints are using the [@safe](https://flask-appbuilder.readthedocs.io/en/v3.2.0/rest_api.html?highlight=exceptions#rest-api) decorator. Given that, this was the highest point in the stack where I felt the error should be handled.
--
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: Provide more inclusive error handling for saved queries [superset]
Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #27644:
URL: https://github.com/apache/superset/pull/27644#discussion_r1539052563
##########
superset/models/sql_lab.py:
##########
@@ -76,7 +77,7 @@ def sql_tables(self) -> list[Table]:
self.database.db_engine_spec.engine, # type: ignore
)
)
- except SupersetSecurityException:
+ except (SupersetSecurityException, TemplateError):
Review Comment:
Shouldn't we propagate the error here and let the caller handle it? Returning empty for an error condition is not the same as returning empty when the select actually does not have a table.
--
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: Provide more inclusive error handling for saved queries [superset]
Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #27644:
URL: https://github.com/apache/superset/pull/27644#discussion_r1539968925
##########
superset/models/sql_lab.py:
##########
@@ -76,7 +77,7 @@ def sql_tables(self) -> list[Table]:
self.database.db_engine_spec.engine, # type: ignore
)
)
- except SupersetSecurityException:
+ except (SupersetSecurityException, TemplateError):
Review Comment:
I just noticed that FlaskAppBuilder does not expect models to throw an error when accessing its properties. We'll probably won't be able to fix this without changing FlaskAppBuilder.
--
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: Provide more inclusive error handling for saved queries [superset]
Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #27644:
URL: https://github.com/apache/superset/pull/27644#discussion_r1539859452
##########
superset/models/sql_lab.py:
##########
@@ -76,7 +77,7 @@ def sql_tables(self) -> list[Table]:
self.database.db_engine_spec.engine, # type: ignore
)
)
- except SupersetSecurityException:
+ except (SupersetSecurityException, TemplateError):
Review Comment:
Wouldn't @safe throw a proper error response in that case? @dpgaspar
> Finally to properly handle all possible exceptions use the safe decorator, that will catch all uncaught exceptions for you and return a proper error response.
So, in the case of a template or security error we would get an error message.
--
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: Provide more inclusive error handling for saved queries [superset]
Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina merged PR #27644:
URL: https://github.com/apache/superset/pull/27644
--
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: Provide more inclusive error handling for saved queries [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #27644:
URL: https://github.com/apache/superset/pull/27644#issuecomment-2018982644
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/27644?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
Attention: Patch coverage is `0%` with `1 lines` in your changes are missing coverage. Please review.
> Project coverage is 60.01%. Comparing base [(`4fce940`)](https://app.codecov.io/gh/apache/superset/commit/4fce940a9c3566c5dded68aa5cbba26fb562ae69?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`b43745e`)](https://app.codecov.io/gh/apache/superset/pull/27644?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
| [Files](https://app.codecov.io/gh/apache/superset/pull/27644?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/models/sql\_lab.py](https://app.codecov.io/gh/apache/superset/pull/27644?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbW9kZWxzL3NxbF9sYWIucHk=) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/27644?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #27644 +/- ##
==========================================
- Coverage 67.39% 60.01% -7.38%
==========================================
Files 1911 1911
Lines 74967 74993 +26
Branches 8353 8353
==========================================
- Hits 50521 45005 -5516
- Misses 22397 27939 +5542
Partials 2049 2049
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/27644/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/27644/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `48.92% <0.00%> (?)` | |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/27644/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/27644/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `53.63% <0.00%> (?)` | |
| [python](https://app.codecov.io/gh/apache/superset/pull/27644/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `62.75% <0.00%> (-15.27%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/27644/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit](https://app.codecov.io/gh/apache/superset/pull/27644/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.77% <0.00%> (?)` | |
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 Sentry](https://app.codecov.io/gh/apache/superset/pull/27644?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).
--
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