Skip to content
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

Prevent exceptions when running fix on dialect fixtures #2818

2 changes: 1 addition & 1 deletion src/sqlfluff/core/rules/analysis/select.py
Expand Up @@ -80,7 +80,7 @@ def get_select_statement_info(
for ref in reference_buffer.copy():
ref_path = segment.path_to(ref)
# is it in a subselect? i.e. a select which isn't this one.
if any(
if ref_path and any(
seg.is_type("select_statement") and seg is not segment for seg in ref_path
):
reference_buffer.remove(ref)
Expand Down
49 changes: 27 additions & 22 deletions src/sqlfluff/core/rules/base.py
Expand Up @@ -802,28 +802,33 @@ def _choose_anchor_segment(

anchor: BaseSegment = segment
child: BaseSegment = segment
for seg in context.parent_stack[0].path_to(segment)[1:-1][::-1]:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review this bit hiding whitespace:

image

# Which lists of children to check against.
children_lists: List[List[BaseSegment]] = []
if filter_meta:
# Optionally check against filtered (non-meta only) children.
children_lists.append(
[child for child in seg.segments if not child.is_meta]
)
# Always check against the full set of children.
children_lists.append(seg.segments)
children: List[BaseSegment]
for children in children_lists:
if edit_type == "create_before" and children[0] is child:
anchor = seg
assert anchor.raw.startswith(segment.raw)
child = seg
break
elif edit_type == "create_after" and children[-1] is child:
anchor = seg
assert anchor.raw.endswith(segment.raw)
child = seg
break
if (
context.parent_stack[0]
and context.parent_stack[0].path_to(segment)
tunetheweb marked this conversation as resolved.
Show resolved Hide resolved
and context.parent_stack[0].path_to(segment)[1:-1]
):
tunetheweb marked this conversation as resolved.
Show resolved Hide resolved
for seg in context.parent_stack[0].path_to(segment)[1:-1][::-1]:
# Which lists of children to check against.
children_lists: List[List[BaseSegment]] = []
if filter_meta:
# Optionally check against filtered (non-meta only) children.
children_lists.append(
[child for child in seg.segments if not child.is_meta]
)
# Always check against the full set of children.
children_lists.append(seg.segments)
children: List[BaseSegment]
for children in children_lists:
if edit_type == "create_before" and children[0] is child:
anchor = seg
assert anchor.raw.startswith(segment.raw)
child = seg
break
elif edit_type == "create_after" and children[-1] is child:
anchor = seg
assert anchor.raw.endswith(segment.raw)
child = seg
break
return anchor
WittierDinosaur marked this conversation as resolved.
Show resolved Hide resolved

@staticmethod
Expand Down
3 changes: 2 additions & 1 deletion src/sqlfluff/rules/L026.py
Expand Up @@ -148,7 +148,8 @@ def _should_ignore_reference(reference, selectable):
# - They are the target table, similar to an INSERT or UPDATE
# statement, thus not expected to match a table in the FROM
# clause.
return any(seg.is_type("into_table_clause") for seg in ref_path)
if ref_path:
tunetheweb marked this conversation as resolved.
Show resolved Hide resolved
return any(seg.is_type("into_table_clause") for seg in ref_path)

@staticmethod
def _get_table_refs(ref, dialect):
Expand Down