exception psycopg.Error from psycopg2 to psycopg 3

From: Paolo De Stefani <paolo(at)paolodestefani(dot)it>
To: Psycopg <psycopg(at)postgresql(dot)org>
Subject: exception psycopg.Error from psycopg2 to psycopg 3
Date: 2022-02-11 17:33:39
Message-ID: 11dedb1fce0dbbd6f125736347685fd5@paolodestefani.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Hi all

Porting my program from psycopg2 to psycopg 3 i found another different
behaviour

This SQL code inside a function:

RAISE EXCEPTION 'Error wrong database' USING HINT = 'You need to use a
different database', ERRCODE = 'PA002';

is catched in python code with:

try:
<execute sql function>
except psycopg.Error as er:
raise PyAppDBError(er.sqlstate, er)

With psycopg2 er.sqlstate is set to 'PA002' in psycopg3 is set to None

Is this an expected behavour ? Is there a way to get the error code in
psycopg3 like it is available in psycopg2 ?
Or maybe Am I doing something wrong ?

Thanks

--
Paolo De Stefani

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2022-02-11 18:47:22 Re: exception psycopg.Error from psycopg2 to psycopg 3
Previous Message Daniele Varrazzo 2022-02-07 12:11:59 psycopg-pool 3.1 released