Deutsch English Français Italiano |
<lk71j4Fnv29U1@mid.individual.net> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Greg Ewing <greg.ewing@canterbury.ac.nz> Newsgroups: comp.lang.python Subject: Re: psycopg2: proper positioning of .commit() within try: except: blocks Date: Mon, 9 Sep 2024 13:33:24 +1200 Lines: 16 Message-ID: <lk71j4Fnv29U1@mid.individual.net> References: <Ztx1sZMGTnA3eLP1@hermes.hilbert.loc> <7cb50df2-9c76-477f-91c9-e149c7637104@aklaver.com> <ZtytJMhyvtExPxfF@hermes.hilbert.loc> <5ee80b84-f04b-454d-ab39-45572e0751a1@aklaver.com> <Zty7ZCMwKQl4C4Id@hermes.hilbert.loc> <4a1b12fc-24b7-4c7e-b1f2-6ec9c5f341c2@aklaver.com> <ZtzDubguRDWXwV-t@hermes.hilbert.loc> <mailman.46.1725744071.2917.python-list@python.org> <lk4ajkFbbnrU1@mid.individual.net> <slrnvdr13p.4dt.jon+usenet@raven.unequivocal.eu> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net WKEYURky4C1G+tW7oCtrRwRxBxbRB/FeXtRBiF93T2gSbZM622 Cancel-Lock: sha1:4wdtAiAk/XmySvhpwIrQS2u9/Lw= sha256:eOkXYV98ly2XvU+NC0NvSC2Hr96IIZUrIcNvqBX6FUU= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Content-Language: en-US In-Reply-To: <slrnvdr13p.4dt.jon+usenet@raven.unequivocal.eu> Bytes: 1788 On 8/09/24 11:03 pm, Jon Ribbens wrote: > On 2024-09-08, Greg Ewing <greg.ewing@canterbury.ac.nz> 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. Good point. Putting the rollback first would be safer/ -- Greg