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

2024-09-08 Thread Karsten Hilbert via Python-list
Am Sun, Sep 08, 2024 at 12:48:50PM +1200 schrieb 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

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

2024-09-08 Thread Karsten Hilbert via Python-list
Am Sun, Sep 08, 2024 at 12:48:50PM +1200 schrieb 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

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

2024-09-08 Thread Rob Cliffe via Python-list
On 07/09/2024 22:20, Karsten Hilbert via Python-list 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 co

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

2024-09-08 Thread Karsten Hilbert via Python-list
Am Sun, Sep 08, 2024 at 02:58:03PM +0100 schrieb Rob Cliffe via Python-list: > >Ugly: > > > > try: > > do something > > except: > > log something > > finally: > > try: > > .commit() > > except: > >

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

2024-09-08 Thread Greg Ewing via Python-list
On 8/09/24 11:03 pm, Jon Ribbens wrote: On 2024-09-08, Greg Ewing wrote: try: do something .commit() except: log something .rollback() What if there's an exception in your exception handler? I'd put the rollback in the 'finally' handler, so it's always called.

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

2024-09-08 Thread Greg Ewing via Python-list
On 9/09/24 2:13 am, Karsten Hilbert wrote: For what it's worth here's the current state of code: That code doesn't inspire much confidence in me. It's far too convoluted with too much micro-management of exceptions. I would much prefer to have just *one* place where exceptions are caught and l