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

2024-09-07 Thread Adrian Klaver
On 9/7/24 14:59, Karsten Hilbert wrote: Am Sat, Sep 07, 2024 at 02:47:49PM -0700 schrieb Adrian Klaver: It is also insufficient because the .commit() itself may elicit exceptions (from the database). Yeah with Serializable that is part of the package: No complaints :-) try:

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

2024-09-07 Thread Karsten Hilbert
Am Sat, Sep 07, 2024 at 02:47:49PM -0700 schrieb Adrian Klaver: > >It is also insufficient because the .commit() itself may > >elicit exceptions (from the database). > > Yeah with Serializable that is part of the package: No complaints :-) > > try: > > do something > > excep

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

2024-09-07 Thread Adrian Klaver
On 9/7/24 14:20, Karsten Hilbert wrote: Am Sat, Sep 07, 2024 at 02:09:28PM -0700 schrieb Adrian Klaver: Right, and this was suggested elsewhere ;) And, yeah, the actual code is much more involved :-D I see that. The question is does the full code you show fail? The code sample you show in

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

2024-09-07 Thread Karsten Hilbert
Am Sat, Sep 07, 2024 at 02:09:28PM -0700 schrieb Adrian Klaver: > >Right, and this was suggested elsewhere ;) > > > >And, yeah, the actual code is much more involved :-D > > > > I see that. > > The question is does the full code you show fail? > > The code sample you show in your original post is

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

2024-09-07 Thread Adrian Klaver
On 9/7/24 13:45, Karsten Hilbert wrote: Am Sat, Sep 07, 2024 at 01:03:34PM -0700 schrieb Adrian Klaver: In the case you show you are doing commit() before the close() so any errors in the transactions will show up then. My first thought would be to wrap the commit() in a try/except and deal w

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

2024-09-07 Thread Karsten Hilbert
Am Sat, Sep 07, 2024 at 01:03:34PM -0700 schrieb Adrian Klaver: > In the case you show you are doing commit() before the close() so any errors > in the > transactions will show up then. My first thought would be to wrap the > commit() in a > try/except and deal with error there. Right, and this

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

2024-09-07 Thread Adrian Klaver
On 9/7/24 12:44, Karsten Hilbert wrote: Am Sat, Sep 07, 2024 at 09:46:03AM -0700 schrieb Adrian Klaver: No I don't but - to my understanding - an ongoing transaction is being closed upon termination of the hosting connection. Unless .commit() is explicitely being issued somewhere in the code

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

2024-09-07 Thread Karsten Hilbert
Am Sat, Sep 07, 2024 at 09:46:03AM -0700 schrieb Adrian Klaver: > >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.o

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

2024-09-07 Thread Adrian Klaver
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#psyco