sql-metadata
sql-metadata copied to clipboard
Unmatched parentheses raises IndexError instead of an informative error message
Python 3.11.8 (main, Aug 16 2024, 10:27:21) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from importlib.metadata import version
>>> import sql_metadata
>>> version('sql_metadata')
'2.11.0'
>>> from sql_metadata import Parser
>>> Parser("SELECT arrayJoin(tags.key)) FROM foo").query_type
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/onkardeshpande/code/snuba/.venv/lib/python3.11/site-packages/sql_metadata/parser.py", line 98, in query_type
_ = self.tokens
^^^^^^^^^^^
File "/Users/onkardeshpande/code/snuba/.venv/lib/python3.11/site-packages/sql_metadata/parser.py", line 167, in tokens
self._determine_closing_parenthesis_type(token=token)
File "/Users/onkardeshpande/code/snuba/.venv/lib/python3.11/site-packages/sql_metadata/parser.py", line 901, in _determine_closing_parenthesis_type
last_open_parenthesis = self._open_parentheses.pop(-1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: pop from empty list
>>>
There is a mismatching parenthesis in SELECT arrayJoin(tags.key)) but the error message is vague. We use ClickHouse at the backend and it shows a correct error on the unmatched parentheses.