"Transaction must be committed using the transaction manager" when doing session.commit()

2,018 views
Skip to first unread message

Guyren G Howe

unread,
Jul 2, 2010, 2:42:06 PM7/2/10
to turbo...@googlegroups.com
I'm doing this:

maker = sessionmaker(autoflush=True, autocommit=False, extension=ZopeTrnsactionExtension())
DBSession = scoped_session(maker)
user = User(…)
DBSession.add(user)
DBSession.commit

At this point, I get a "Transaction must be committed using the transaction manager" exception. Can anyone suggest why?

FWIW, datamanager is throwing the exception because zope_transaction.get().status is 'Active' rather than 'Committing'.

Diez B. Roggisch

unread,
Jul 2, 2010, 4:12:07 PM7/2/10
to turbo...@googlegroups.com
As the doctor says: if it hurts, don't do it. In this case, don't
commit. A middleware will do that for you. If you need an id (sa is
lazy), flush.

Diez

> --
> You received this message because you are subscribed to the Google
> Groups "TurboGears" group.
> To post to this group, send email to turbo...@googlegroups.com.
> To unsubscribe from this group, send email to turbogears+...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
> .
>

mark.mch...@gmail.com

unread,
Jul 2, 2010, 5:57:20 PM7/2/10
to TurboGears
And if you absolutely need to finish the transaction, do import
transaction, transaction.commit() because we are using a transaction
manager on top of sqlalchemy for when you want multi-database
transactions, or other transaction events that aren't SQLAlchemy
database commits.

Guyren G Howe

unread,
Jul 2, 2010, 6:04:55 PM7/2/10
to turbo...@googlegroups.com
Thanks.

I'd like to ask: is this documented somewhere? Because I spent hours looking, and didn't find it…

Mark Ramm

unread,
Jul 2, 2010, 10:59:46 PM7/2/10
to turbo...@googlegroups.com
It's mentioned here:

http://turbogears.org/2.0/docs/main/Wiki20/wiki20.html#initializing-the-tables

and is somewhat described here:

http://turbogears.org/2.1/docs/main/Config/SQLAlchemy.html?highlight=commit

but we should definitely do better.

Heck, I even wonder if the benifit of the transaction manger is less
than the cost of people getting confused because the standard
SQLAlchemy way does not work.

Perhaps we should make it optional at some point. I do think it's a
great feature when you have multiple databases, or when you want to
delay some other actions until you know the commit went in ok.

--Mark Ramm

> --
> You received this message because you are subscribed to the Google Groups "TurboGears" group.
> To post to this group, send email to turbo...@googlegroups.com.
> To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.
>
>

--
Mark Ramm-Christensen
email: mark at compoundthinking dot com
blog: www.compoundthinking.com/blog

Michael Pedersen

unread,
Jul 13, 2010, 2:25:06 PM7/13/10
to turbo...@googlegroups.com
Sorry I've been out for so long. Count me as +1 for getting rid of the zope transaction manager. I've had to deal with it on several occasion, and the only thing I *ever* use it for is "import transaction; transaction.commit();" and that goes against all SA docs I've ever read.

It might have other uses, and it might be great, but it threw me for a loop. Hell, it still does. Whenever I write a command line tool that uses the model, sometimes I need it, sometimes I don't, and I have yet to figure out the pattern.
Michael J. Pedersen
My IM IDs: Jabber/pede...@icelus.tzo.com, ICQ/103345809, AIM/pedermj022171
          Yahoo/pedermj2002, MSN/pederm...@hotmail.com

Reply all
Reply to author
Forward
0 new messages