Google Groups Home
Help | Sign in
Help with implicit transactions
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
George Sakkis  
View profile
 More options Apr 16 2007, 11:54 am
From: "George Sakkis" <george.sak...@gmail.com>
Date: Mon, 16 Apr 2007 15:54:38 -0000
Local: Mon, Apr 16 2007 11:54 am
Subject: Help with implicit transactions
Is there any way I can force a COMMIT within an exposed method ? I am
using SqlAlchemy with PostgreSQL and I am creating a few records that
I need to use for subsequent SELECTs within the same method. Although
I do flush() them and get their assigned IDs, subsequent explicit
SELECTs (using SA's select(), not the data mappers) fail to see the
changes.

Alternatively, is there an easy way to turn off the transaction
altogether for a specific method ? The workaround shown in [1] looks
messy and error prone.

George

[1]
http://groups.google.com/group/turbogears/tree/browse_frm/thread/a81b...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alberto Valverde  
View profile
 More options Apr 16 2007, 12:18 pm
From: Alberto Valverde <albe...@toscat.net>
Date: Mon, 16 Apr 2007 18:18:17 +0200
Local: Mon, Apr 16 2007 12:18 pm
Subject: Re: [TurboGears] Help with implicit transactions

On Apr 16, 2007, at 5:54 PM, George Sakkis wrote:

> Is there any way I can force a COMMIT within an exposed method ? I am
> using SqlAlchemy with PostgreSQL and I am creating a few records that
> I need to use for subsequent SELECTs within the same method. Although
> I do flush() them and get their assigned IDs, subsequent explicit
> SELECTs (using SA's select(), not the data mappers) fail to see the
> changes.

How are you obtaining the engine when you use SA's select? You should  
use the same connection the transaction is using so you see its  
changes, check out [1]

> Alternatively, is there an easy way to turn off the transaction
> altogether for a specific method ? The workaround shown in [1] looks
> messy and error prone.

Not that I'm aware of.

Alberto

[1] http://tinyurl.com/35uter


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
George Sakkis  
View profile
 More options Apr 16 2007, 12:53 pm
From: "George Sakkis" <george.sak...@gmail.com>
Date: Mon, 16 Apr 2007 16:53:26 -0000
Local: Mon, Apr 16 2007 12:53 pm
Subject: Re: Help with implicit transactions
On Apr 16, 12:18 pm, Alberto Valverde <albe...@toscat.net> wrote:

> On Apr 16, 2007, at 5:54 PM, George Sakkis wrote:

> > Is there any way I can force a COMMIT within an exposed method ? I am
> > using SqlAlchemy with PostgreSQL and I am creating a few records that
> > I need to use for subsequent SELECTs within the same method. Although
> > I do flush() them and get their assigned IDs, subsequent explicit
> > SELECTs (using SA's select(), not the data mappers) fail to see the
> > changes.

> How are you obtaining the engine when you use SA's select? You should
> use the same connection the transaction is using so you see its
> changes, check out [1]

I use:

from turbogears import database as db
engine=db.get_engine()

How can I access the implicit transaction created by TG or its
connection object ?

George


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alberto Valverde  
View profile
 More options Apr 16 2007, 2:51 pm
From: Alberto Valverde <albe...@toscat.net>
Date: Mon, 16 Apr 2007 20:51:59 +0200
Local: Mon, Apr 16 2007 2:51 pm
Subject: Re: [TurboGears] Re: Help with implicit transactions

On Apr 16, 2007, at 6:53 PM, George Sakkis wrote:

You'll need access to the transaction instance. Unfortunately it's a  
local variable inside database.sa_rwt. Perhaps it should be bound to  
cherrypy.request so you could do:

connection = engine.connect()
cherrypy.request.sa_transaction.add(connection)

then connection.execute(table.select()) # or whatever

as described in the mentioned link. Can you try this patch see if it  
works?

Index: turbogears/database.py
===================================================================
--- turbogears/database.py      (revision 2824)
+++ turbogears/database.py      (working copy)
@@ -336,7 +336,8 @@
[run_with_transaction.when("_use_sa()")]
def sa_rwt(func, *args, **kw):
      log.debug("New SA transaction")
-    transaction = session.create_transaction()
+    req = cherrypy.request
+    transaction = req.sa_transaction = session.create_transaction()
      try:
          retval = func(*args, **kw)
          transaction.commit()

Alberto


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Janzert  
View profile
 More options Apr 16 2007, 4:47 pm
From: Janzert <janz...@gmail.com>
Date: Mon, 16 Apr 2007 16:47:16 -0400
Local: Mon, Apr 16 2007 4:47 pm
Subject: Re: Help with implicit transactions

It would be nice if instead of holding onto a local reference to the
transaction it used the one in the request object to commit and rollback
(i.e. get rid of the transaction variable above and change all
references to req.sa_transaction). I believe this would solve the
problem where people want to be able to rollback the transaction and
then start a new one within a controller.

Janzert


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alberto Valverde  
View profile
 More options Apr 16 2007, 4:56 pm
From: Alberto Valverde <albe...@toscat.net>
Date: Mon, 16 Apr 2007 22:56:57 +0200
Local: Mon, Apr 16 2007 4:56 pm
Subject: Re: [TurboGears] Re: Help with implicit transactions

On Apr 16, 2007, at 10:47 PM, Janzert wrote:

Good point. Mind posting opening a tickjet at the Trac with a patch?

Thanks,
Alberto


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Janzert  
View profile
 More options Apr 16 2007, 6:07 pm
From: Janzert <janz...@gmail.com>
Date: Mon, 16 Apr 2007 18:07:26 -0400
Local: Mon, Apr 16 2007 6:07 pm
Subject: Re: Help with implicit transactions

Done, ticket #1359.

Janzert


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alberto Valverde  
View profile
 More options Apr 16 2007, 6:32 pm
From: Alberto Valverde <albe...@toscat.net>
Date: Tue, 17 Apr 2007 00:32:02 +0200
Local: Mon, Apr 16 2007 6:32 pm
Subject: Re: [TurboGears] Re: Help with implicit transactions

On Apr 17, 2007, at 12:07 AM, Janzert wrote:

Great, thanks!

Alberto


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Mariani  
View profile
 More options Apr 17 2007, 5:00 am
From: Marco Mariani <marco.mari...@prometeia.it>
Date: Tue, 17 Apr 2007 11:00:09 +0200
Local: Tues, Apr 17 2007 5:00 am
Subject: Re: [TurboGears] Re: Help with implicit transactions

Alberto Valverde wrote:
> You'll need access to the transaction instance. Unfortunately it's a  
> local variable inside database.sa_rwt. Perhaps it should be bound to  
> cherrypy.request so you could do:

> connection = engine.connect()
> cherrypy.request.sa_transaction.add(connection)

> then connection.execute(table.select()) # or whatever

> as described in the mentioned link. Can you try this patch see if it  
> works?

The following works for me, without any patch. Is there a reason it
should not?

conn = session.context.get_current().connection(SomeMappedClass)

conn.execute(....).fetchall()


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google