-
Notifications
You must be signed in to change notification settings - Fork 14.8k
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
No saved queries are shown if SQLGlot is unable to parse any of the saved queries #27581
Comments
I'm not a fan of (3). I know we've had regressions with the introduction of #26476, but we also had multiple CVEs caused by (2) might be OK, since it's the result of fixing a CVE. But let's try to fix this before going down that route. One thing we could do is add a @john-bodley what happened to your PR that traversed the Jinja nodes? It seems like we need a helper function |
@john-bodley to be clear, my suggestion is to do something like this (pseudocode): def get_referenced_tables(template: str) -> set[Table]:
tables = get_tables_from_jinja_macros(template)
sql = render_jinja(template, mode="dummy") # do not run DB queries to fetch latest partitions
return tables & ParsedQuery(sql).tables |
@betodealmeida sorry I scrubbed my previous comment after realizing what you meant in terms of a helper function. I was thinking along the same lines as your pseudo code. I'll work on a fix. |
Fixed by #27470 |
Bug description
@betodealmeida and @michael-s-molina I've found another wrinkle with the SQLGlot integration which was introduced in #26476. The
/savedqueryview/list/
which displays a table of your saved queries includes a column named "Tables" which uses theParsedQuery
class to extract the tables names from every saved query.These saved queries may contain Jinja templating—including the
latest[_sub]_partition]
macros resulting in SQL statements which SQLGlot is unable to parse—especially if the is no proper escaping. The resulting UX is users see this error and no saved queries are listed.The long-term fix (as discussed previously) of having a multi-phase approach to extracting the table names without having to render aspects of the Jinja templates should resolve this, however I'm not entirely sure what the short-term solution should be.
Some possible solutions could be:
latest[_sub]_partition]
Jinja macros.sqlparse
and only introduce SQLGlot when i) the various workflows are hardened, and ii) [SIP-117] Improve SQL parsing is fully implemented. For context we've had about half a dozen reported regressions with the SQLGlot integration and thus we might not quite be ready for its widespread release.How to reproduce the bug
SELECT 1
.SELECT '{{ trino.latest_partition('foo') }}'
./superset/welcome/
and see theThere was an issue fetching your saved queries: [object Response]
error./savedqueryview/list/
and see theAn error occurred while fetching Saved queriess: Unable to parse SQL ...
error and observe that no saved queries are listed.Screenshots/recordings
No response
Superset version
3.1.1
Python version
3.9
Node version
16
Browser
Chrome
Additional context
No response
Checklist
The text was updated successfully, but these errors were encountered: