public inbox for [email protected]
help / color / mirror / Atom feedFrom: Adrian Klaver <[email protected]>
To: Karsten Hilbert <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: Re: psycopg2: proper positioning of .commit() within try: except: blocks
Date: Sat, 7 Sep 2024 09:46:03 -0700
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
On 9/7/24 08:48, Karsten Hilbert wrote:
> Dear all,
>
> unto now I had been thinking this is a wise idiom (in code
> that needs not care whether it fails to do what it tries to
> do^1):
>
> conn = psycopg2.connection(...)
In the above do you have:
https://www.psycopg.org/docs/extensions.html#psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE
psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE
Or is that in some other concurrent transaction?
> curs = conn.cursor()
> try:
> curs.execute(SOME_SQL)
> except PSYCOPG2-Exception:
> some logging being done, and, yes, I
> can safely inhibit propagation^1
> finally:
> conn.commit() # will rollback, if SOME_SQL failed
It will if you use with conn:, otherwise it up to you to do the rollback()
Are you are doing a rollback() in except PSYCOPG2-Exception: ?
--
Adrian Klaver
[email protected]
view thread (10+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: psycopg2: proper positioning of .commit() within try: except: blocks
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox