[RELEASE] Python 3.13.0RC2, 3.12.6, 3.11.10, 3.10.15, 3.9.20, and 3.8.20 are now available!

2024-09-07 Thread Łukasz Langa via Python-list
Hi there! A big joint release today. Mostly security fixes but we also have the final release candidate of 3.13 so let’s start with that! Python 3.13.0RC2 Final opportunity to test and find any show-stopper bugs before we bless and release 3.13.0 final on October 1st. Get it here: Python Releas

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

2024-09-07 Thread Karsten Hilbert via Python-list
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(...) curs = conn.cursor() try: curs.execute(SOME_SQL) except PSYCOPG2-Exception:

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

2024-09-07 Thread Rob Cliffe via Python-list
On 07/09/2024 16:48, Karsten Hilbert via Python-list 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(...) curs = conn.cursor() try: c

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

2024-09-07 Thread Karsten Hilbert via Python-list
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 Karsten Hilbert via Python-list
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 Karsten Hilbert via Python-list
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 Greg Ewing via Python-list
On 8/09/24 9:20 am, Karsten Hilbert wrote: try: do something except: log something finally: .commit() cadence is fairly Pythonic and elegant in that it ensures the the .commit() will always be reached regardless of exception