I would never want to start the transaction *inside* the connection proxy.  The 
transactional context for a particular set of operations should be enclosing 
the full set of operations.   Unless below, "self.connection" is a different 
connection that is ad-hoc.   In which case just procure a new connection from 
the engine inside the proxy class.



On Apr 27, 2011, at 9:56 AM, bool wrote:

> 
> I want to some updates before doing any insert. So I needed the
> above.
> 
> Now the issue I am facing is that I need all these updates and the
> current insert to be in a transaction. That is either all should be
> successful or none.
> 
> How is that possible with a connection proxy (something like below)?
> 
> 
> 
> ===========================================================
> class MyProxy(ConnectionProxy):
>    def execute(self, conn, execute, clauseelement, *multiparams,
> **params):
> 
>             if isinstance(clauseelement, Insert):
>                  trans = self.connection.begin()
>                 try:
>                    # Do some updates
>                    # Execute the current insert also
>                    .......
>                   trans.commit()
>                except:
>                   trans.rollback()
> =============================================================
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" 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/sqlalchemy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en.

Reply via email to