You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I searched the issues and found no similar issues.
What Happened
The AM07 linting rule seems to have a hard crash when unions and parentheses are involved.
The issue may be similar to #5401, but that one specifically mentions dbt_utils.union_relations, while I can reproduce seemingly the same error with a simple SQL union.
Expected Behaviour
No internal errors
Observed Behaviour
CRITICAL [AM07] Applying rule AM07 to 'models/200_WRK/w_test_union.sql' threw an Exception: list index out of range
Traceback (most recent call last):
File "/home/tim/.cache/pypoetry/virtualenvs/byta-OvIvHU96-py3.11/lib/python3.11/site-packages/sqlfluff/core/rules/base.py", line 507, in crawl
res = self._eval(context=context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tim/.cache/pypoetry/virtualenvs/byta-OvIvHU96-py3.11/lib/python3.11/site-packages/sqlfluff/rules/ambiguous/AM07.py", line 217, in _eval
set_segment_select_sizes, resolve_wildcard = self._get_select_target_counts(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tim/.cache/pypoetry/virtualenvs/byta-OvIvHU96-py3.11/lib/python3.11/site-packages/sqlfluff/rules/ambiguous/AM07.py", line 196, in _get_select_target_counts
cnt, res = self.__resolve_selectable(selectable, query)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tim/.cache/pypoetry/virtualenvs/byta-OvIvHU96-py3.11/lib/python3.11/site-packages/sqlfluff/rules/ambiguous/AM07.py", line 167, in __resolve_selectable
_cols, _resolved = self.__resolve_selectable_wildcard(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tim/.cache/pypoetry/virtualenvs/byta-OvIvHU96-py3.11/lib/python3.11/site-packages/sqlfluff/rules/ambiguous/AM07.py", line 135, in __resolve_selectable_wildcard
_cols, _resolved = self.__resolve_wild_query(cte)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tim/.cache/pypoetry/virtualenvs/byta-OvIvHU96-py3.11/lib/python3.11/site-packages/sqlfluff/rules/ambiguous/AM07.py", line 88, in __resolve_wild_query
return self.__resolve_selectable(query.selectables[0], query)
~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
== [models/200_WRK/w_test_union.sql] FAIL
L: 3 | P: 9 | AM07 | Unexpected exception: list index out of range;
Could you
| open an issue at
| https://github.com/sqlfluff/sqlfluff/issues ?
You can
| ignore this exception for now, by adding '-- noqa: AM07'
| at the end
of line 3
[ambiguous.set_columns]
All Finished 📜 🎉!
How to reproduce
I narrowed it down to this tiny test case:
with
foo as (
(select1)
union all
(select2)
)
select*from foo
Note that the following do not crash:
with
foo as (
select1unionselect2
)
select*from foo
with
foo as (
(select1as a)
union
(select2as a)
)
select a
from foo
Search before asking
What Happened
The AM07 linting rule seems to have a hard crash when unions and parentheses are involved.
The issue may be similar to #5401, but that one specifically mentions
dbt_utils.union_relations
, while I can reproduce seemingly the same error with a simple SQL union.Expected Behaviour
No internal errors
Observed Behaviour
How to reproduce
I narrowed it down to this tiny test case:
Note that the following do not crash:
Dialect
postgres
Version
Configuration
(Basically just the
sqlfmt
recommendations as stated here)Are you willing to work on and submit a PR to address the issue?
Code of Conduct
The text was updated successfully, but these errors were encountered: