From: Ants Aasma Date: Wed, 12 Mar 2008 21:40:11 +0000 (+0000) Subject: Session.execute can now find binds from metadata X-Git-Tag: rel_0_4_5~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e15813837f4fb050b305e7c6020c1292f0ee1e8e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Session.execute can now find binds from metadata --- diff --git a/CHANGES b/CHANGES index 732aeaefa4..01f0546eda 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,8 @@ CHANGES - fixed bug which was preventing synonym() attributes from being used with inheritance + + - Session.execute can now find binds from metadata 0.4.4 ------ diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index a01c444c08..91b4463f26 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -712,6 +712,8 @@ class Session(object): if self.bind is not None: return self.bind + elif isinstance(clause, sql.expression.ClauseElement) and clause.bind is not None: + return clause.bind elif mapper is None: raise exceptions.UnboundExecutionError("Could not locate any mapper associated with SQL expression") else: diff --git a/test/orm/session.py b/test/orm/session.py index 1d6742d8ad..fdffe4b578 100644 --- a/test/orm/session.py +++ b/test/orm/session.py @@ -99,6 +99,21 @@ class SessionTest(TestBase, AssertsExecutionResults): sess.execute(users.insert(), params=dict(user_id=2, user_name='fred')) assert sess.execute(users.select()).fetchall() == [(1, 'ed'), (2, 'fred')] sess.close() + + @engines.close_open_connections + def test_bind_from_metadata(self): + Session = sessionmaker() + sess = Session() + mapper(User, users) + + sess.execute(users.insert(user_name='Johnny')) + + assert len(sess.query(User).all()) == 1 + + sess.execute(users.delete()) + + assert len(sess.query(User).all()) == 0 + sess.close() @testing.unsupported('sqlite', 'mssql') # TEMP: test causes mssql to hang @engines.close_open_connections