From: | Rory Campbell-Lange <rory(at)campbell-lange(dot)net> |
---|---|
To: | Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com> |
Cc: | psycopg(at)lists(dot)postgresql(dot)org |
Subject: | Re: Plans for 2.8 |
Date: | 2018-10-04 13:55:01 |
Message-ID: | 20181004135501.2rvzcg3li4plo77b@campbell-lange.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | psycopg |
On 04/10/18, Daniele Varrazzo (daniele(dot)varrazzo(at)gmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Daniele Varrazzo | 2018-10-04 14:05:51 | Re: Plans for 2.8 |
Previous Message | Federico Di Gregorio | 2018-10-04 13:27:20 | Re: Plans for 2.8 |