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

Fix: ensure Expression is not an iterable to avoid inf. loops #2280

Merged
merged 1 commit into from
Sep 21, 2023

Conversation

georgesittas
Copy link
Collaborator

Before:

>>> import sqlglot
>>> for x in sqlglot.parse_one("select 1"):
...     pass
...
<infinite loop - hangs>

After:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sqlglot/expressions.py", line 764, in __iter__
    raise TypeError(f"'{self.__class__.__name__}' object is not iterable")
TypeError: 'Select' object is not iterable

Comment on lines -383 to 386
return hasattr(value, "__iter__") and not isinstance(value, (str, bytes))
from sqlglot import Expression

return hasattr(value, "__iter__") and not isinstance(value, (str, bytes, Expression))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure how expensive this import can be; it was the simplest solution, but perhaps a try-except block where we call iter(value) is faster / better?

Copy link
Owner

Choose a reason for hiding this comment

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

nah it's fine

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cool

@georgesittas georgesittas merged commit 76b7077 into main Sep 21, 2023
@georgesittas georgesittas deleted the jo/avoid_inf_loop branch September 21, 2023 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants