Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g84Jr-0000Wa-19 for psycopg@arkaria.postgresql.org; Thu, 04 Oct 2018 14:09:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g84Jp-0003kN-1J for psycopg@arkaria.postgresql.org; Thu, 04 Oct 2018 14:09:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g84Jo-0003kD-Eu for psycopg@lists.postgresql.org; Thu, 04 Oct 2018 14:09:32 +0000 Received: from [2a01:7e00::f03c:91ff:fe18:393b] (helo=campbell-lange.net) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g84Jh-0007VS-8K for psycopg@lists.postgresql.org; Thu, 04 Oct 2018 14:09:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=campbell-lange.net; s=it; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=P/wRt7TsRBO/occtK5qtFG/QLeTxAASYtLR0Am8uoe8=; b=OdrvwPqfyRyXJChFwjXZL7669 WndsiBla2Mc2LGklFUEa8Ys6LiQwIsBNSJfgUFyC3L7Z5PSKfHF8l1Fa14Q1mR7lBg3Al4IdXsFgF SS+TJg5NMETAQpu8sLvvf1PbfhNkMztBPf9KefD0jbPOJyEcBC6kZW/OyTzfBRSfLbXXI=; Received: from [85.189.61.90] (helo=rory-t450s) by campbell-lange.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1g84Jf-00013G-Jv; Thu, 04 Oct 2018 14:09:23 +0000 Received: from rory by rory-t450s with local (Exim 4.89) (envelope-from ) id 1g845l-0006ER-QW; Thu, 04 Oct 2018 14:55:01 +0100 Date: Thu, 4 Oct 2018 14:55:01 +0100 From: Rory Campbell-Lange To: Daniele Varrazzo Cc: psycopg@lists.postgresql.org Subject: Re: Plans for 2.8 Message-ID: <20181004135501.2rvzcg3li4plo77b@campbell-lange.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:7e00::f03c:91ff:fe18:393b (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 04/10/18, Daniele Varrazzo (daniele.varrazzo@gmail.com) wrote: > The feature I'm the most excited about (and worried about its > reception) is to raise a different exception for every postgres error > message (see #682) . For instance `SELECT * FROM wrong_name` will > raise `UndefinedTable` rather than `ProgrammingError`. Currently > handling a specific exception requires catching a broader class and > looking at the pgcode: > > try: > cur.execute("lock table %s in access exclusive mode nowait" % name) > except psycopg2.OperationalError as e: > if e.pgcode == psycopg2.errorcodes.LOCK_NOT_AVAILABLE: > locked = True > else: > raise > > This can become a much more natural: > > try: > cur.execute("lock table %s in access exclusive mode nowait" % name) > except psycopg2.errors.LockNotAvailable: > locked = True > > The error classes are generated automatically from Postgres source > code and are subclasses of the previously existing ones, so existing > code should be unaffected. I'd be happy to have input about the > feature and suggestions before releasing it. Hi Daniele The greater depth of exception reporting looks great to me, particularly if they are subclasses of the existing ones. Regards Rory