On Jan 26, 2011, at 7:47 PM, Michael Bayer wrote: > > On Jan 26, 2011, at 6:32 PM, A.M. wrote: > >> Well, I spoke too soon :( What is the mistake in the following sample code >> which causes the COMMITs to be emitted? Setting autocommit to either True or >> False emits the same SQL. I think this is a case of staring at the same code >> too long causing brain damage- thanks for your patience and help! >> >> from sqlalchemy.engine import create_engine >> from sqlalchemy.orm.session import sessionmaker >> from sqlalchemy.orm import scoped_session >> from sqlalchemy.schema import DDL,MetaData,Table >> >> engine = create_engine('postgresql://localhost/test',echo=True) >> session = scoped_session(sessionmaker(bind=engine)) >> metadata = MetaData() >> metadata.bind = engine >> >> Table('test1',metadata) >> Table('test2',metadata) >> metadata.create_all() > > metadata.create_all() looks at the "bind" attribute, then uses it to execute > each DDL statement. The "bind" here is an engine so it uses connectionless > execution. connectionless execution is usually autocommit as documented > here: > http://www.sqlalchemy.org/docs/core/connections.html#connectionless-execution-implicit-execution > > to emit create_all() in a transaction: > > conn = engine.connect() > with conn.begin(): > metadata.create_all(conn)
Ugh- thanks for being patient with a noob- I had erroneously assumed that the creation of a session would assume responsibility for transaction management like the zope transaction handler. It makes sense now that the session is exclusively specific to ORM management- the section "Joining a Session into an External Transaction" helped to clear things up- there is indeed some interaction between connection and session transactions. Cheers, M -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.