On Dec 5, 2013, at 2:24 PM, Michael Bayer <mike...@zzzcomputing.com> wrote:
> > On Dec 5, 2013, at 1:25 PM, Jonathan Vanasco <jonat...@findmeon.com> wrote: > >> >> i'm looking at moving some raw sql in twisted to SqlAlchemy and have a >> question. >> >> I have a multi-threaded twisted daemon that tends to generate a lot of race >> conditions on a few tables that are frequently hit. >> >> I get integrity errors from something like this : >> >> domain = """SELECT * FROM domains WHERE ...."" >> if not domain : >> domain = """INSERT INTO domain VALUES .... >> >> the fix was : >> >> domain = """SELECT * FROM domains WHERE ....""" >> if not domain : >> try: >> savepoint = db.savepoint() >> """INSERT INTO domain VALUES ....""" >> except psycopg2.IntegrityError : >> savepoint,release() >> domain = """SELECT * FROM domains WHERE ...."" >> >> is there a way to catch an integrity error like this with SqlAlchemy ? >> >> i'm trying to get away from directly using psycopg2, it's getting too >> annoying to maintain raw sql. > > sure, catch sqlalchemy.ext.IntegrityError instead. that should be sqlalchemy.exc.IntegrityError
signature.asc
Description: Message signed with OpenPGP using GPGMail