]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Session.execute can now find binds from metadata
authorAnts Aasma <ants.aasma@gmail.com>
Wed, 12 Mar 2008 21:40:11 +0000 (21:40 +0000)
committerAnts Aasma <ants.aasma@gmail.com>
Wed, 12 Mar 2008 21:40:11 +0000 (21:40 +0000)
CHANGES
lib/sqlalchemy/orm/session.py
test/orm/session.py

diff --git a/CHANGES b/CHANGES
index 732aeaefa4c724684ac7b82089cba09e84a460d1..01f0546edab6e48cec13acb3c2344e1257085255 100644 (file)
--- 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
 ------
index a01c444c085f43a24bdf5c8ea4a96bdd7c72d0b1..91b4463f26e5ffe2311796ea2927848e2ce37b22 100644 (file)
@@ -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:
index 1d6742d8ad2bd2d87989834005eeec7e5c933282..fdffe4b578e55e54ed01018651e50faf8b31bd2c 100644 (file)
@@ -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