Path: ...!fu-berlin.de!uni-berlin.de!not-for-mail From: Karsten Hilbert Newsgroups: comp.lang.python Subject: Re: psycopg2: proper positioning of .commit() within try: except: blocks Date: Mon, 9 Sep 2024 10:56:47 +0200 Lines: 20 Sender: Message-ID: References: <7cb50df2-9c76-477f-91c9-e149c7637104@aklaver.com> <5ee80b84-f04b-454d-ab39-45572e0751a1@aklaver.com> <4a1b12fc-24b7-4c7e-b1f2-6ec9c5f341c2@aklaver.com> <62133ebd-a4a3-471b-9acc-3a988b4fcbd7@btinternet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de mFg5+wZEYkuVj6PsaZ3c5AdkLyBi/NaeaHC381FvgXZg== Cancel-Lock: sha1:bnpqE4lNQwE7GE+dEf1KjGMlQIs= sha256:xmvh2ehHXgjr/hAhMhG1oiwWXW7sYVtEpeuj6AV8wVw= Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org Authentication-Results: mail.python.org; dkim=pass reason="2048-bit key; unprotected key" header.d=gmx.net header.i=karsten.hilbert@gmx.net header.b=SSIG8PuM; dkim-adsp=pass; dkim-atps=neutral X-Spam-Status: OK 0.040 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'received:212.227': 0.07; 'gpg': 0.09; 'karsten': 0.09; 'schrieb': 0.09; '1713': 0.16; '2024': 0.16; 'exception.': 0.16; 'greg': 0.16; 'logs': 0.16; 'received:212.227.15': 0.16; 'subject:() ': 0.16; 'subject:proper': 0.16; 'subject:try': 0.16; 'larger': 0.17; 'to:addr:python-list': 0.20; 'code': 0.23; "doesn't": 0.32; 'sep': 0.32; 'header:In-Reply-To:1': 0.34; 'mon,': 0.36; "it's": 0.37; 'two': 0.39; 'skip:u 20': 0.39; 'both': 0.40; 'me.': 0.62; 'received:212': 0.62; 'top': 0.65; 'caught': 0.67; 'them,': 0.70; 'confidence': 0.76; 'catching': 0.84; 'exceptions': 0.84; 'subject:within': 0.84; 'differently': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1725872207; x=1726477007; i=karsten.hilbert@gmx.net; bh=6+1RLm0Xe5p0hoFw2QnjuHUsgQTqTsMjIWt5zGWt3+0=; h=X-UI-Sender-Class:Date:From:To:Subject:Message-ID:References: MIME-Version:Content-Type:In-Reply-To:Content-Transfer-Encoding: cc:content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=SSIG8PuMC0cmsYWFS+W7PB2JHrJ4idsZfn6REqDWixyaNUsaRRMVULz6YEn1v7ub IOuMm6ODQ1CwYeLX03W/LJ6POJohziZB37Q/905Wib0lX5L8w8B71Xi26ICLeEhwV EU9RqikRhOVkLVd4HxqHpu7WHTzIx1dh0kgxiUP8RZK5kVWI4rG613vx0wM9TghTn Dq95cNJIA9HZJd3d0rBgayfnHxIfGHVj3NYjNoy3aIl1KOMkzvL74KomV9cxvOuk3 JusCrhavYOXRGleOKI3/2a5fu/+EDSmErF7xW+ge86uYjNp6whQrH8uT/PKFHoIXY CZzzpHvDo+q+6/T7DA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Content-Disposition: inline In-Reply-To: Ma_X_il-Followup-to: d Re_X_turn-receipt-to: Karsten.Hilbert@gmx.net Di_X_sposition-Notification-To: Karsten.Hilbert@gmx.net X-Confi_X_rm-Reading-To: Karsten.Hilbert@gmx.net X-Pri_X_ority: 2 (High) X-Provags-ID: V03:K1:niU7Wm7AQDU9dEWbxpGmHdwThuVuAQJbD3V1EqoPKs0mQ3PiImd 4Bbpsojz49MjvMjkZxy1Hy75bWSeQAJKirH+i6kfmFN4LoSre3tUJxv2+LJS3s8f2vfoXEL 4lPRAzd53B1p3wE4zoV49ttBWZR4VSU881l2C0bXs1O2xI9X3xzipD6cLQyUwOLd5k5KNE9 80gWRg/yz020if+7xs5Ww== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:Xrjc0qaix/o=;/abE06uqZh8fRaRfhFGv0GI/hMr 41RBTyLDH9LR/B5YZiQ51SRG82s0IvEYrGpYwb2id64Ofnk0PuxaTqTSY8zVmxFJ5Bllk5w5n hmb2PuFSyLweYebEnFFYI2Ps+14j7wyzkXS86FllKqboOFvjJLvdO5Z18XcpdftREBVclfuor fM5pF8+Q78CwexQ078Hnp4hsZ0QiNG+CtbUqLUkZj1nGgVV/tv2M58SQ2yfTu/xg+b3MA+vt5 K27gROfjwmSjYurGooF+Id4Yh+u1FL0yIsCIKwN1/FDFKP24gERTXakcTfJd5BHa76V97FOto 3NqTUQqAvgHa26SUrNN3bG4boS/OZcJB5MKLQ4cj2Kw6TsJ1IDy7a5lMlkfsiMy7sS7GaOdCZ Qw+YtDl05nDaRA9cWyvVP8Qi5XGBzw+8LIuoycog5KSlUN5UdT9K9I7t/p/HWfYCvsUo2E657 1EMqg04njn4kdHUYsoNbsqIXNkdKV8TyA/Teqf2RMwIzw2+ztXou3OqRKxDxWJiJyUW41IqLy 6K/yrTQ+Hy5ldJ1EfiNlweS7hybNFkhqyQmIUIBzXGeyqqBv976GrrS9SQVXcGwg3Q+6ogFGs zYft6qI4DEYp8VrgJGgF81P6JDFmt+xHml3OsBJfps6GDQIArtc+EGLraxpGSNQUUIyVQxXph g46evDGyikZgfQfuOMQFTsTd4fP78D3l7TQ5CZMXvsZkubOM0cetrnijKPpJL03RVwNsri1gC rwkkuu65RbhihyYY1ibaTCjSzwVEuvtGFoyr5QVNi7F9yDvJyLsz/qmXN24FT0t142WSCbZtU Fh1JkAnVYBGSFPzo/Rwzd+IQ== X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.39 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <7cb50df2-9c76-477f-91c9-e149c7637104@aklaver.com> <5ee80b84-f04b-454d-ab39-45572e0751a1@aklaver.com> <4a1b12fc-24b7-4c7e-b1f2-6ec9c5f341c2@aklaver.com> <62133ebd-a4a3-471b-9acc-3a988b4fcbd7@btinternet.com> Bytes: 6449 Am Mon, Sep 09, 2024 at 01:48:32PM +1200 schrieb Greg Ewing via Python-lis= t: > That code doesn't inspire much confidence in me. It's far too > convoluted with too much micro-management of exceptions. It is catching two exceptions, re-raising both of them, except for re-raising one of them as another kind of exception. What would you doing differently and how ? > I would much prefer to have just *one* place where exceptions are > caught and logged. There's, of course, a top level handler which logs and user-displays-as-appropriate any exceptions. This is code from a much larger codebase. Karsten =2D- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B