the way you are mixing the SessionTransaction and straight table
inserts is not how SessionTransaction was made to work....the
SessionTransaction does not begin any transaction at all until a
connection or engine is added to the transaction.  this happens only
when you explicitly add() to it, or a query is performed via the
session directly, uponwhich that connection is added to the
transaction.  at that point, a transaction is opened on the connection
and is added to a list, where all subsequent queries for that
connection or that connection's engine will use that transaction.

the two main patterns whereby SessionTransaction can be intermingled
with straight SQL queries are described at:

http://www.sqlalchemy.org/docs/unitofwork.myt#unitofwork_transaction_sql

both of which involve explicit connections.

Since you are using the "threadlocal" engine strategy, your example
below might also work if you simply say:

   trans.add(engine)

before performing your inserts, at which point the transaction will get
a hold of the "contextual connection", which is the thread-local
connection.  If that sounds confusing its because it is; the entire
"threadlocal" idea is downplayed heavily in the 0.2 and 0.3 series for
the very reason that its non-explicit and therefore confusing.


Dominik Neumann wrote:
> Hello list,
>
> i'm using a multithreaded appserver (Webware) for the application.
> in application-scope (global) i define:
>
> dbEngine = sqlalchemy.create_engine(self.setting('SystemDBPool'),
> module=psycopg2,strategy='threadlocal')
> metadata = sqlalchemy.BoundMetaData(dbEngine)
>
> All following table-definitions and mappers are bound to metadata.
> For example:
>
> wiki_page = Table('wiki_page', metadata,
>                                Column('id', Integer, primary_key=True)
>                                .....
>                                )
>
> in the servlet-scope (should be thread-safe) i use always the same
> procedure of doing transactions etc...
>
> sess = sqlalchemy.objectstore.session
> trans = sess.create_transaction()
>
> try:
>     table1.insert().execute( somedata )
>     table2.insert().execute( somedata )
>
>     trans.commit()
> except:
>     trans.rollback()
>
>
> in my case, the table2-insert raises an exception. but the table1-insert
> are committed anyway.
> 
> Has anybody a solution for this?
> 
> Many thanks
> 
> dn


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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