diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-05-14 10:29:55 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-05-14 11:49:01 -0400 |
| commit | 31b793894f7e45503ebebd28d93fc95d92768aa1 (patch) | |
| tree | b7092db03574a71e6e3a2036a0d19dc55c0df5c0 /lib/sqlalchemy/orm/session.py | |
| parent | 0d5508d77653b37368ff9de22307c154cc90cf71 (diff) | |
| download | sqlalchemy-31b793894f7e45503ebebd28d93fc95d92768aa1.tar.gz | |
Consult plugin_subject for non-ORM enabled stmts in get_bind()
Enhanced the bind resolution rules for :meth:`_orm.Session.execute` so that
when a non-ORM statement such as an :func:`_sql.insert` construct
nonetheless is built against ORM objects, to the greatest degree possible
the ORM entity will be used to resolve the bind, such as for a
:class:`_orm.Session` that has a bind map set up on a common superclass
without specific mappers or tables named in the map.
Fixes: #6484
Change-Id: Iaa711b7f2c7451377b50af63029f37c4375a6f7e
Diffstat (limited to 'lib/sqlalchemy/orm/session.py')
| -rw-r--r-- | lib/sqlalchemy/orm/session.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index cdf3a1585..e4a9b9046 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -1997,6 +1997,15 @@ class Session(_SessionClassMethods): clause = mapper.persist_selectable if clause is not None: + plugin_subject = clause._propagate_attrs.get( + "plugin_subject", None + ) + + if plugin_subject is not None: + for cls in plugin_subject.mapper.class_.__mro__: + if cls in self.__binds: + return self.__binds[cls] + for obj in visitors.iterate(clause): if obj in self.__binds: return self.__binds[obj] |
