On Sun, 2011-07-03 at 16:27 -0700, YP wrote:
> Hi,
> 
> i'm using Pyramid with SQLAlchemy, and i have some problems with
> ZopeTransactionManager and SQLAlchemy Session. It's that i have to
> create a new session after every transaction.commit() or
> transaction.abort() or dbsession.rollback(), then i have to manually
> populate this new session with all objects that have been added or
> loaded into the old session, like this:
> 
> dbsession = DBSession()
> dbsession.add(a)
> dbsession.add(b)
> c = dbsession.query(SomeClass).first()
> ..... etc etc .....
> transaction.commit()
> #and now i have to do it all again:
> dbsession = DBSession()
> dbsession.add(a)
> dbsession.add(b)
> c = dbsession.query(SomeClass).first()
> ..... etc etc .....
> 
> While without transaction manager, i can just do dbsession.commit() or
> dbsession.rollback(), and the session remains alive, i don't have to
> create and populate new one. This is much better, unless there is some
> really easy way to copy everything from old session to new one  (which
> i don't see).
> 
> I understand that if i remove transaction manager from the pipeline,
> i'll have to manually take care about transactions, commit or rollback
> somewhere near the app exit point. As far as i can see, that's
> basically all what the transaction manager is doing. Is that right, or
> am i missing any other important operations usually performed by the
> transaction manager?

I guess the real question is this:  why are you issuing manual commit
statements at all?  If the answer is "i want newly added items to get an
id", use dbsession.flush() instead.  Is there another reason?

- C


-- 
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