superset: Unable to parse SQL (Dialects.TSQL)
Bug description
After upgrade from 4.0.1 to 4.1.1 I encountered an issue with permission
DB engine Error
You may have an error in your SQL statement. Unable to parse script
This error occurred for users to whom I assigned specific permissions on the dbo schema only. When I changed the permissions to full access for the entire database id:, the issue was resolved. I noticed that this problem only happens with the mssql.py engine, while the others (MySQL, PostgreSQL, and Oracle) are working fine.
Log:
WARNING:superset.sql_parse:Unable to parse SQL (Dialects.TSQL): Template(body=[Output(nodes=[TemplateData(data='SELECT ...')])])
Screenshots/recordings
Superset version
master / latest-dev
Python version
3.11
Node version
I don’t know
Browser
Not applicable
Additional context
No response
Checklist
- I have searched Superset docs and Slack and didn’t find a solution to my problem.
- I have searched the GitHub issue tracker and didn’t find a similar bug report.
- I have checked Superset’s logs for errors and if I found a relevant Python stacktrace, I included it here as text in the “additional context” section.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (13 by maintainers)
Awesome! I tried the workaround by adding
ENABLE_TEMPLATE_PROCESSING = Truein thesuperset_config.py, but it didn’t work. However, after applying the fix you suggested insql_parse.py, it’s working perfectly. I really appreciate your help!Fix is out, as a workaround you can enable the
ENABLE_TEMPLATE_PROCESSINGfeature flag.OK, I was able to repro this, working on a fix.
Thanks! I’ll take a look!
Assigned it to you temporarily, @Habeeb556, since we need the query to investigate this more.
Right, we need to parse the query in order to determine which catalogs/schemas/tables are being accessed when the user doesn’t have full access to the database. If the user has full access we just don’t parse the query.
In the past this was done using
sqlparse, which is very lenient, so it was much harder to get an error when parsing SQL. The problem was that it was much easier to trick the parser, and the parsing was not dialect-specific, so we had many security holes.We’re currently in the process of switching the parsing to
sqlglot, which has dialect-specific parsing. Unfortunately some engines don’t have correspondingsqlglotdialects, and we have to fallback to a generic parser.For MSSQL we use the T-SQL dialect, which AFAIK is the correct one. If you can share the query that’s causing problems (anonymized is fine) we can take a look, and file a ticket upstream with
sqlglot.@betodealmeida this might also use your help! 🙏