On Sat, May 2, 2015 at 12:09 AM, <[email protected]> wrote: > In my web app I sometimes use SQLAlchemy expression language rather than > ORM. But then DBSession is unaware of my commands. What is the proper way of > making DBSession flush and commit SQL in this use case?
The SQLAlchemy session talks to the transaction manager via the zope.sqlalchemy package. However if you run raw sql commands (DBSession.execute) it cannot tell if things have been changed and need to be committed. You have two options: 1) After running your query flag the session as changed so that the transaction will realize it needs to be committed. Do this via zope.sqlalchemy.mark_changed(DBSession). 2) Have the session default to a changed state thus it will always do a commit instead of a rollback. This would be slightly less performant because you'd be doing a commit even when nothing changed, but can be more convenient. zope.sqlalchemy.register(DBSession, 'changed'). -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout.
