--- /dev/null
+.. change::
+ :tags: bug, orm, regression
+ :tickets: 7936
+
+ Fixed regression where the change in #7861, released in version 1.4.33,
+ that brought the :class:`.Insert` construct to be partially recognized as
+ an ORM-enabled statement did not properly transfer the correct mapper /
+ mapped table state to the :class:`.Session`, causing the
+ :meth:`.Session.get_bind` method to fail for a :class:`.Session` that was
+ bound to engines and/or connections using the :paramref:`.Session.binds`
+ parameter.
bind_arguments,
is_reentrant_invoke,
):
+ bind_arguments["clause"] = statement
+ try:
+ plugin_subject = statement._propagate_attrs["plugin_subject"]
+ except KeyError:
+ assert False, "statement had 'orm' plugin but no plugin_subject"
+ else:
+ bind_arguments["mapper"] = plugin_subject.mapper
+
return (
statement,
util.immutabledict(execution_options),
lambda User: {"clause": mock.ANY, "mapper": inspect(User)},
"e1",
),
+ (
+ lambda User: update(User)
+ .values(name="not ed")
+ .where(User.name == "ed"),
+ lambda User: {"clause": mock.ANY, "mapper": inspect(User)},
+ "e1",
+ ),
+ (
+ lambda User: insert(User).values(name="not ed"),
+ lambda User: {
+ "clause": mock.ANY,
+ "mapper": inspect(User),
+ },
+ "e1",
+ ),
)
def test_bind_through_execute(
self, statement, expected_get_bind_args, expected_engine_name
)
cls.mapper_registry.map_imperatively(Address, addresses)
+ @testing.combinations("table", "mapper", "both", argnames="bind_type")
+ @testing.combinations(
+ "update", "insert", "delete", argnames="statement_type"
+ )
+ def test_get_bind_scenarios(self, connection, bind_type, statement_type):
+ """test for #7936"""
+
+ User = self.classes.User
+
+ if statement_type == "insert":
+ stmt = insert(User).values(
+ {User.id: 5, User.age: 25, User.name: "spongebob"}
+ )
+ elif statement_type == "update":
+ stmt = (
+ update(User)
+ .where(User.id == 2)
+ .values({User.name: "spongebob"})
+ )
+ elif statement_type == "delete":
+ stmt = delete(User)
+
+ binds = {}
+ if bind_type == "both":
+ binds = {User: connection, User.__table__: connection}
+ elif bind_type == "mapper":
+ binds = {User: connection}
+ elif bind_type == "table":
+ binds = {User.__table__: connection}
+
+ with Session(binds=binds) as sess:
+ sess.execute(stmt)
+
def test_illegal_eval(self):
User = self.classes.User
s = fixture_session()