Re: psycopg2: proper positioning of .commit() within try: except: blocks

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: psycopg2: proper positioning of .commit() within try: except: blocks
Дата
Msg-id 7cb50df2-9c76-477f-91c9-e149c7637104@aklaver.com
обсуждение исходный текст
Ответ на psycopg2: proper positioning of .commit() within try: except: blocks  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Ответы Re: psycopg2: proper positioning of .commit() within try: except: blocks
Список psycopg
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
adrian.klaver@aklaver.com




В списке psycopg по дате отправления: