Re: Implications of transaction manager removal

16 views
Skip to first unread message

Chris McDonough

unread,
Jul 3, 2011, 7:50:17 PM7/3/11
to pylons-...@googlegroups.com
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


YP

unread,
Jul 3, 2011, 7:27:12 PM7/3/11
to pylons-discuss
Thanks.
yp.

YP

unread,
Jul 3, 2011, 8:34:36 PM7/3/11
to pylons-discuss
If that was just the commit(), that would be ok (though i'd like to
have the ability to commit easily whenever i want, just like
sqlalchemy allows me). But i have to start a new session after
dbsession.rollback() too.

Thanks.
yp.

Chris McDonough

unread,
Jul 3, 2011, 8:57:52 PM7/3/11
to pylons-...@googlegroups.com
On Sun, 2011-07-03 at 17:34 -0700, YP wrote:
> If that was just the commit(), that would be ok (though i'd like to
> have the ability to commit easily whenever i want, just like
> sqlalchemy allows me). But i have to start a new session after
> dbsession.rollback() too.

Same question I guess.. what's the rationale for rolling back yourself?

- C

YP

unread,
Jul 4, 2011, 6:03:33 AM7/4/11
to pylons-discuss
On Jul 4, 4:57 am, Chris McDonough <chr...@plope.com> wrote:
> Same question I guess.. what's the rationale for rolling back yourself?
>

At least i have to be able to catch any database errors and then
continue using the dbsession:

#some stuff with dbsession
try:
dbsession.flush()
except:
dbsession.rollback()
#some other stuff with dbsession

Still, my initial question - if i remove the TM from the pipeline,
the only thing i'll have to do is manually commit / rollback, or is
there anything else?

Thanks.
yp.
Reply all
Reply to author
Forward
0 new messages