That doesn't sound right. Session.commit() issues the commit regardless of whether or not flush() had any work to do. The usage of Session.execute() takes place in the scope of the Session's transaction so work is definitely begun as well.
from sqlalchemy import create_engine from sqlalchemy.orm import Session e = create_engine('sqlite:///test.db', echo=True) s = Session(e) s.execute("CREATE TABLE foo (data VARCHAR)") s.execute("INSERT INTO foo (data) VALUES ('data1')") s.commit() s.close() e = create_engine('sqlite:///test.db', echo=True) assert e.execute("SELECT * FROM foo").fetchall() == [('data1',)] On Dec 16, 2010, at 2:37 PM, Kent wrote: > From time to time I find I need or prefer "dropping into SQL" for > certain tasks, in the midst of making the majority of my database > changes through sqlalchemy's objects; for example, I may use > session.execute(sql). > > I would like these changes to be committed later along with the sqla > session objects *if and only if* the session issues a commit. > However, I've observed that if the *only* database changes were made > via session.execute(), then session.commit() believes there is nothing > to commit, so the "commit" isn't issued to the database. > > Is there a better way to approach what I am trying to accomplish? > Is there a way to tell a session "by the way, you have changes that > you don't know about, so when it comes time to commit, please do so"? > > Thanks very much, as always, > Kent > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@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. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.