Hi Jerry,

On 13/05/2011 01:31, jerry wrote:
Everything is still wrapped in one big transaction --

->  for item in items_query.all():
(Pdb)
2011-05-13 08:23:54,109 INFO sqlalchemy.engine.base.Engine.0x...68cc
BEGIN (implicit)
2011-05-13 08:23:54,122 INFO sqlalchemy.engine.base.Engine.0x...68cc
SELECT ...

I don't think this is anything to do with Pyramid.

Read the docs for sessionmaker, particularly those about autocommit:
http://www.sqlalchemy.org/docs/orm/session.html#sqlalchemy.orm.session.sessionmaker

So, you have a transaction created for you, but you can manage it yourself:

session = DBSession()
session.bind = ...your engine...

for item in items_query.all():
   try:
       ...do stuff...
   except:
       session.abort()
   else:
       session.commit()

Now, personally, I like the ZopeTransactionExtension 'cos it lets me spell the above in a nicer way and synchronise transactions across things like sending mail, writing files to disk, etc.

I also like http://packages.python.org/mortar_rdb/use.html, where the pattern would become:

from mortar_rdb import registerSession,getSession
import transaction

registerSession('sqlite://')

session = getSession()
for item in session.query(...).all():
    with transaction:
       ...do stuff...

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
           - http://www.simplistix.co.uk

--
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to