On Thursday, October 14, 2010 13:05:46 Juan Antonio Ibáñez wrote:
> Trying next code:
> 
> -------------------------
> try:
>   session.begin(subtransactions=True)
>   session.add(importe)
>   session.flush()
>   nimportados += 1
> except Exception as ex:
>   log.debug(ex)
>   session.rollback()
>   nerroneos += 1
> -------------------------
> 
> I can see into the log:
> 
> -------------------------
> 12:55:45,598 INFO  [sqlalchemy.engine.base.Engine.0x...f1ac] BEGIN
> 12:55:45,600 INFO  [sqlalchemy.engine.base.Engine.0x...f1ac] INSERT
> INTO importes (tarifas_id, prefijo, destino, importe, tipo, pc, psi,
> ps, sg) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
> 12:55:45,600 INFO  [sqlalchemy.engine.base.Engine.0x...f1ac] [u'1',
> 'PREFIJO', 'DESTINO', 'IMPORTE', u'', 0, 60, 60, 0]
> 12:55:45,601 INFO  [sqlalchemy.engine.base.Engine.0x...f1ac] ROLLBACK
> 12:55:45,603 DEBUG [svbpanel.controllers] (IntegrityError) (1062,
> "Duplicate entry 'PREFIJO' for key 'prefijo'") u'INSERT INTO importes
> (tarifas_id, prefijo, destino, importe, tipo, pc, psi, ps, sg) VALUES
> (%s, %s, %s, %s, %s, %s, %s, %s, %s)' [u'1', 'PREFIJO', 'DESTINO',
> 'IMPORTE', u'', 0, 60, 60, 0]
> 12:55:45,603 DEBUG [svbpanel.controllers] The transaction is inactive
> due to a rollback in a subtransaction.  Issue rollback() to cancel the
> transaction.
> -------------------------
> 
> and "InvalidRequestError: The transaction is closed" into TG web debug
> messages.
> 
> It seems to auto run the ROLLBACK but. Any idea?

To me, it doesn't look as if there is actually a sub-transaction started. For 
that, there would be needed 2 begins.

Also your above code is broken, because you don't commit the subtransaction.

There are two things to do now:
  
 - make a self-contained (no TG2!!) example the shows the wrong behavior, and 
present that at the SA mailing list.

 - forget about this overall approach. Which is IHMO the best solution. The 
integrity rules of your DB are a safety net, not means of control flow. Is 
there a reason you can't lock e.g. tables for importing?

Diez

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

Reply via email to