iercan opened a new issue, #36067:
URL: https://github.com/apache/superset/issues/36067

   ### Bug description
   
   The schema name "analyze" in MongoDB causes Superset to fail when adding a 
dataset or selecting a table from SQL Lab, making the database unusable. I've 
tried it on 4.1.4, 6.0.0rc2 and master. All of them are failing. I've also 
tried to add sql mutator to add quote around analyze but it didn't help. 
   
   ```
   2025-11-11 
07:56:01,619:WARNING:superset.views.error_handling:SupersetErrorException
   Traceback (most recent call last):
     File "/app/superset/sql/parse.py", line 553, in _parse
       statements = sqlglot.parse(script, dialect=dialect)
     File "/app/.venv/lib/python3.10/site-packages/sqlglot/__init__.py", line 
102, in parse
       return Dialect.get_or_raise(read or dialect).parse(sql, **opts)
     File 
"/app/.venv/lib/python3.10/site-packages/sqlglot/dialects/dialect.py", line 
1083, in parse
       return self.parser(**opts).parse(self.tokenize(sql), sql)
     File "/app/.venv/lib/python3.10/site-packages/sqlglot/parser.py", line 
1623, in parse
       return self._parse(
     File "/app/.venv/lib/python3.10/site-packages/sqlglot/parser.py", line 
1692, in _parse
       expressions.append(parse_method(self))
     File "/app/.venv/lib/python3.10/site-packages/sqlglot/parser.py", line 
1933, in _parse_statement
       expression = self._parse_set_operations(expression) if expression else 
self._parse_select()
     File "/app/.venv/lib/python3.10/site-packages/sqlglot/parser.py", line 
3246, in _parse_select
       query = self._parse_select_query(
     File "/app/.venv/lib/python3.10/site-packages/sqlglot/parser.py", line 
3342, in _parse_select_query
       from_ = self._parse_from()
     File "/app/.venv/lib/python3.10/site-packages/sqlglot/parser.py", line 
3640, in _parse_from
       this=self._parse_table(joins=joins, consume_pipe=consume_pipe),
     File "/app/.venv/lib/python3.10/site-packages/sqlglot/parser.py", line 
4117, in _parse_table
       self._parse_table_parts(schema=schema, is_db_reference=is_db_reference)
     File "/app/.venv/lib/python3.10/site-packages/sqlglot/parser.py", line 
4048, in _parse_table_parts
       self.raise_error(f"Expected table name but got {self._curr}")
     File "/app/.venv/lib/python3.10/site-packages/sqlglot/parser.py", line 
1736, in raise_error
       raise error
   sqlglot.errors.ParseError: Expected table name but got <Token token_type: 
TokenType.ANALYZE, text: analyze, line: 2, col: 12, start: 15, end: 21, 
comments: []>. Line 2, Col: 12.
     SELECT *
   FROM analyze.events
   LIMIT 100
   
   The above exception was the direct cause of the following exception:
   
   Traceback (most recent call last):
     File "/app/.venv/lib/python3.10/site-packages/flask/app.py", line 1484, in 
full_dispatch_request
       rv = self.dispatch_request()
     File "/app/.venv/lib/python3.10/site-packages/flask/app.py", line 1469, in 
dispatch_request
       return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
     File 
"/app/.venv/lib/python3.10/site-packages/flask_appbuilder/security/decorators.py",
 line 109, in wraps
       return f(self, *args, **kwargs)
     File "/app/superset/views/base_api.py", line 120, in wraps
       duration, response = time_function(f, self, *args, **kwargs)
     File "/app/superset/utils/core.py", line 1409, in time_function
       response = func(*args, **kwargs)
     File "/app/superset/utils/log.py", line 304, in wrapper
       value = f(*args, **kwargs)
     File "/app/superset/databases/api.py", line 1090, in table_metadata
       payload = database.db_engine_spec.get_table_metadata(database, table)
     File "/app/superset/db_engine_specs/base.py", line 1097, in 
get_table_metadata
       return get_table_metadata(database, table)
     File "/app/superset/databases/utils.py", line 100, in get_table_metadata
       "selectStar": database.select_star(
     File "/app/superset/models/core.py", line 774, in select_star
       return self.db_engine_spec.select_star(
     File "/app/superset/db_engine_specs/base.py", line 1668, in select_star
       sql = SQLScript(sql, engine=cls.engine).format()
     File "/app/superset/sql/parse.py", line 1231, in __init__
       self.statements = statement_class.split_script(script, engine)
     File "/app/superset/sql/parse.py", line 591, in split_script
       cls(ast=ast, engine=engine) for ast in cls._parse(script, engine) if ast
     File "/app/superset/sql/parse.py", line 556, in _parse
       raise SupersetParseError(
   superset.exceptions.SupersetParseError: Error parsing near 'analyze' at line 
2:12
   ``` 
   
   ### Screenshots/recordings
   
   _No response_
   
   ### Superset version
   
   master / latest-dev
   
   ### Python version
   
   3.9
   
   ### Node version
   
   16
   
   ### Browser
   
   Chrome
   
   ### Additional context
   
   _No response_
   
   ### Checklist
   
   - [x] I have searched Superset docs and Slack and didn't find a solution to 
my problem.
   - [x] I have searched the GitHub issue tracker and didn't find a similar bug 
report.
   - [x] 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.


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to