Hello! I am dealing with Turbogears and SQL Alchemy. I need to make one import from a CSV file to a MySQL DB. I need also to controll which rows fails on import. I am working with the next code inside a loop:
------------------------ try: session.begin(subtransactions=True) session.add(importe) session.flush() nimportados += 1 except Exception as ex: log.debug(ex) session.rollback() nerroneos += 1 ------------------------ During exec I get: ------------------------- 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. ------------------------- Peopel on TG2 group told me about the appearance of not init the subtransaction. I thing TG2 init a own transaction in an automatic way so I should work with subtransactions (I think) Commiting instead flushing doesn't work... Any idea about this problem? Regards -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.