diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-29 16:38:03 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-29 16:41:28 -0400 |
commit | 7002b2b0b109e70b47d4ae4f5f6a4d7df5586f21 (patch) | |
tree | 9652d3ef8e9bd1bae574222915bc20a0c99b6a46 /lib/sqlalchemy/sql/selectable.py | |
parent | 75d1a599519fde61c9ea2c9d8c935f1e420b8333 (diff) | |
download | sqlalchemy-7002b2b0b109e70b47d4ae4f5f6a4d7df5586f21.tar.gz |
Ensure iterable passed to Select is not a mapped class
Fixed regression caused by :ticket:`5395` where tuning back the check for
sequences in :func:`_sql.select` now caused failures when doing 2.0-style
querying with a mapped class that also happens to have an ``__iter__()``
method. Tuned the check some more to accommodate this as well as some other
interesting ``__iter__()`` scenarios.
Fixes: #6300
Change-Id: Idf1983fd764b91a7d5fa8117aee8a3def3cfe5ff
Diffstat (limited to 'lib/sqlalchemy/sql/selectable.py')
-rw-r--r-- | lib/sqlalchemy/sql/selectable.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index ff830dbf6..43ba0da4c 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -56,6 +56,7 @@ from .elements import UnaryExpression from .visitors import InternalTraversal from .. import exc from .. import util +from ..inspection import inspect if util.TYPE_CHECKING: from typing import Any @@ -4959,8 +4960,17 @@ class Select( """ if ( args - and hasattr(args[0], "__iter__") - and not isinstance(args[0], util.string_types + (ClauseElement,)) + and ( + isinstance(args[0], list) + or ( + hasattr(args[0], "__iter__") + and not isinstance( + args[0], util.string_types + (ClauseElement,) + ) + and inspect(args[0], raiseerr=False) is None + and not hasattr(args[0], "__clause_element__") + ) + ) ) or kw: return cls.create_legacy_select(*args, **kw) else: |