Thanks for the reply!

Since I create objects concurrently I can not predict and therefore not 
pre-select all rows which could possibly provoke IntegrityErrors. 

On the other hand Session.merge() seams to provide the functionality which 
could resolve my problem. In my setup many processes create a number of 
objects which could occur multiple times (in other words throw an 
IntegrityError on commit). That can happen in one process (which I can 
handle otherwise), in between multiple processes and between a process and 
the consistent state in the database (which is my main problem ATM). 

I just read the corresponding part in the SQLAlchemy docs 
<http://docs.sqlalchemy.org/en/rel_0_9/orm/session_state_management.html#merging>.
 So 
if I use Session.merge() with the load=True argument (instead of 
Session.add()) the session should create the corresponding object if it 
does not exists, avoid duplicates within one session and also update an 
existing entry in the database?

Also it seems that merging only works for primary keys. So if I had the 
problem with an unique key, I still would have to parse the exception, 
right?

On Thursday, February 19, 2015 at 5:29:56 PM UTC+1, Michael Bayer wrote:
>
>
> Maurice Schleußinger <[email protected] <javascript:>> wrote: 
>
> > Is there no other way? 
> > 
> > 
> http://stackoverflow.com/questions/27635933/how-can-i-know-which-fiels-cause-integrityerror-when-inserting-into-a-table-with/27884632#27884632
>  
> > 
> > Parsing an exception with regex just doesn't feel right… 
>
>
> The two other ways are that you can pre-select the rows, or use a MERGE / 
> upsert approach (you’d have to roll that yourself). 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to