Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 3FCC3595B16 for ; Fri, 2 Dec 2011 17:22:41 -0400 (AST) Received: from exprod7og121.obsmtp.com ([64.18.2.20]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RWaZ5-00056p-2z for pgsql-hackers@postgresql.org; Fri, 02 Dec 2011 21:22:41 +0000 Received: from mail-ww0-f47.google.com ([74.125.82.47]) (using TLSv1) by exprod7ob121.postini.com ([64.18.6.12]) with SMTP ID DSNKTtlBkHe9SbB0DEOp9qfKdmYkzrg3GSvh@postini.com; Fri, 02 Dec 2011 13:22:38 PST Received: by mail-ww0-f47.google.com with SMTP id dr10so1985471wgb.4 for ; Fri, 02 Dec 2011 13:22:24 -0800 (PST) Received: by 10.227.209.146 with SMTP id gg18mr55707wbb.6.1322860944006; Fri, 02 Dec 2011 13:22:24 -0800 (PST) Received: from [192.168.1.100] (dsl-hkibrasgw2-ff6cc300-200.dhcp.inet.fi. [88.195.108.200]) by mx.google.com with ESMTPS id eo4sm147555wib.19.2011.12.02.13.22.21 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 02 Dec 2011 13:22:22 -0800 (PST) Message-ID: <4ED9418C.1070801@enterprisedb.com> Date: Fri, 02 Dec 2011 23:22:20 +0200 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.2.23) Gecko/20111010 Icedove/3.1.15 MIME-Version: 1.0 To: =?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= CC: Mika Eloranta , pgsql-hackers@postgresql.org Subject: Re: PL/Python SQL error code pass-through References: <0174B71F-7940-4819-BDC8-95EC8C9BA833@ohmu.fi> <4ECDFB26.1090203@wulczer.org> <4ECE5FA5.6060506@enterprisedb.com> <4ECEBDA5.4000600@wulczer.org> In-Reply-To: <4ECEBDA5.4000600@wulczer.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -4.2 (----) X-Archive-Number: 201112/93 X-Sequence-Number: 199345 On 24.11.2011 23:56, Jan Urbański wrote: > On 24/11/11 16:15, Heikki Linnakangas wrote: >> On 24.11.2011 10:07, Jan Urbański wrote: >>> On 23/11/11 17:24, Mika Eloranta wrote: >>>> [PL/Python in 9.1 does not preserve SQLSTATE of errors] >>> >>> Oops, you're right, it's a regression from 9.0 behaviour. >>> >>> The fix looks good to me, I changed one place to indent with tabs >>> instead of spaces and added a regression test. (Forgot to mention earlier: I committed the patch to master and REL9_1_STABLE) > In case of SPI errors we're preserving the following from the original > ErrorData: > > * sqlerrcode (as of Mika's patch) > * detail > * hint > * query > * internalpos > > that leaves us with the following which are not preserved: > > * message > * context > * detail_log > > The message is being constructed from the Python exception name and I > think that's useful. The context is being taken by the traceback string. > I'm not sure if detail_log is ever set in these types of errors, > probably not? So I guess we're safe. Ok. > The problem with storing the entire ErrorData struct is that this > information has to be transformed to Python objects, because we attach > it to the Python exception that gets raised and in case it bubbles all > the way up to the topmost PL/Python function, we recover these Python > objects and use them to construct the ereport call. While the exception > is inside Python, user code can interact with it, so it'd be hard to > have C pointers to non-Python stuff there. Hmm, can the user also change the fields in the exception within python code, or are they read-only? Is the spidata attribute in the exception object visible to user code? -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com