Thanks Mike!
Your last suggestion was the best (ans easiest) solution, I guess I
just needed someone to point that out to me ;-) Since I want the whole
transaction to either succeed or fail, there's no need to use
SAVEPOINTs.
Cheers, Simon
On 3 Jul., 19:55, Michael Bayer [EMAIL PROTECTED] wrote:
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
throughhttp://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
athttp://www.sqlalchemy.org/docs/05/session.html#unitofwork_managing_sa...
. 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 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
-~--~~~~--~~--~--~---