Skip to content

Commit

Permalink
fix macbre#390 AttributeError: 'NoneType' object has no attribute 'no…
Browse files Browse the repository at this point in the history
…rmalized'
  • Loading branch information
Byunk committed Oct 11, 2023
1 parent 366a8b5 commit d1b4984
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions sql_metadata/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ def tables_aliases(self) -> Dict[str, str]:
token.last_keyword_normalized in TABLE_ADJUSTMENT_KEYWORDS
and (token.is_name or (token.is_keyword and not token.is_as_keyword))
and not token.next_token.is_as_keyword
and not token.value in RELEVANT_KEYWORDS
):
if token.previous_token.is_as_keyword:
# potential <DB.<SCHEMA>.<TABLE> as <ALIAS>
Expand Down
4 changes: 4 additions & 0 deletions sql_metadata/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ def is_alias_of_self(self) -> bool:
end_of_column = end_of_column.find_nearest_token(
[",", "FROM"], value_attribute="normalized", direction="right"
)

if end_of_column is EmptyToken:
return False

return end_of_column.previous_token.normalized == self.normalized

@property
Expand Down

0 comments on commit d1b4984

Please sign in to comment.