On Jul 3, 2008, at 1:09 PM, Simon wrote:

>
> Hi all,
>
> I have a transactional session which save()s multiple objects to
> multiple tables where each object potentially violates a unique
> primary key or just a unique key constraint. At flush() time, MySQL
> returns an IntegrityError which specifies the value of the offending
> key and the key's number within its table (i.e. first key, second
> key...), but I cannot from this information figure out which of my
> objects is the culprit. Any suggestions on how to solve this problem?
> Ideally, I would like to rollback() the whole transaction when such an
> error occurs, regenerate the keys on the offending object, and repeat
> until commit() succeeds.


use SQLA 0.5 if you'd like to rollback() a session and continue using  
the objects within.  Read through 
http://www.sqlalchemy.org/docs/05/session.html#unitofwork_using_rolling 
  and elsewhere to see what the SQLA contract is regarding sessions,  
errors and rolling back.   It's also worthwhile to give SAVEPOINT a  
try, which allows partial transactions to commit and is described at 
http://www.sqlalchemy.org/docs/05/session.html#unitofwork_managing_savepoint 
  .  In particular, some databases such as Postgres do not allow the  
transaction to continue if an integrity error is raised, necessitating  
the use of SAVEPOINT, or just querying the table beforehand (which is  
the traditional approach to this problem). 
   

--~--~---------~--~----~------------~-------~--~----~
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