diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-01-09 08:53:57 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-01-09 09:29:31 -0500 |
| commit | eb9d00c4b4f4f15e871aa9ea88d41023054c6e97 (patch) | |
| tree | 04935d2a29ade93983d09b7da06f9131e3c41779 /lib/sqlalchemy/orm/session.py | |
| parent | a76f4cbb7d3066f71b035b29e511eb811b810c9c (diff) | |
| download | sqlalchemy-eb9d00c4b4f4f15e871aa9ea88d41023054c6e97.tar.gz | |
accept TableClause through mapped selectable chain
type annotation somehow decided that TableClause doesn't have
primary key fields which is not the case at all. In particular
the "views" recipe relies on TableClause so adding a restriction
like this does not make any sense.
It seems the issue was to open this up for typing, by allowing
TableClause out as far as ddl.sort_tables() typing is passing
for now. Support it out in get_bind() etc.
Fixes: #9071
Change-Id: If0e22e0e7df7bee0ff4b295b0ffacfbc6b7a0142
Diffstat (limited to 'lib/sqlalchemy/orm/session.py')
| -rw-r--r-- | lib/sqlalchemy/orm/session.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 0298b17a7..5bcb22a08 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -80,6 +80,7 @@ from ..sql import coercions from ..sql import dml from ..sql import roles from ..sql import Select +from ..sql import TableClause from ..sql import visitors from ..sql.base import CompileState from ..sql.schema import Table @@ -152,7 +153,7 @@ _PKIdentityArgument = Union[Any, Tuple[Any, ...]] _BindArguments = Dict[str, Any] _EntityBindKey = Union[Type[_O], "Mapper[_O]"] -_SessionBindKey = Union[Type[Any], "Mapper[Any]", "Table", str] +_SessionBindKey = Union[Type[Any], "Mapper[Any]", "TableClause", str] _SessionBind = Union["Engine", "Connection"] JoinTransactionMode = Literal[ @@ -2439,7 +2440,7 @@ class Session(_SessionClassMethods, EventTarget): if TYPE_CHECKING: assert isinstance(insp, Inspectable) - if isinstance(insp, Table): + if isinstance(insp, TableClause): self.__binds[insp] = bind elif insp_is_mapper(insp): self.__binds[insp.class_] = bind @@ -2480,7 +2481,7 @@ class Session(_SessionClassMethods, EventTarget): """ self._add_bind(mapper, bind) - def bind_table(self, table: Table, bind: _SessionBind) -> None: + def bind_table(self, table: TableClause, bind: _SessionBind) -> None: """Associate a :class:`_schema.Table` with a "bind", e.g. an :class:`_engine.Engine` or :class:`_engine.Connection`. |
