public inbox for [email protected]  
help / color / mirror / Atom feed
'Psycopg2.errors' not referenced in packaged
2+ messages / 2 participants
[nested] [flat]

* 'Psycopg2.errors' not referenced in packaged
@ 2020-11-19 15:41 Patrick Starrenburg <[email protected]>
  2020-11-19 16:37 ` Re: 'Psycopg2.errors' not referenced in packaged Daniele Varrazzo <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Patrick Starrenburg @ 2020-11-19 15:41 UTC (permalink / raw)
  To: psycopg

Hi

I am using psycopg2 in a Django app. In my code I am checking for various
exceptions, one of which is foreign key violations.

I see in the psycopg2 docs https://www.psycopg.org/docs/errors.html that
ForeignKeyViolation
is under the base IntegrityError exception. I would like to be able to
specifically catch, and respond to the ForeignKeyViolation error. I am
coding using the recommendation in the docs (below).

It is working (a forced FK violation is specifically caught) my question is
though that in my IDE (PyCharm) it reports that it cannot find the
reference 'errors' and I cannot use dotted links to drill down to the
errors.ForeignKeyViolation function.

I can type psycopg2.IntegrityError and reference to it is found (and I see
that it is listed in the __init.py__ file).

When I Google this some say it is a PyCharm bug, some say that PyCharm is
following the Python package convention.

Can anyone advise.

Thanks in advance.

Patrick

try:
    cursor_wsr.close()
    conn.commit()
    conn.close()
except psycopg2.errors.ForeignKeyViolation as err:

Cannot find reference 'errors' in '__init__.py | __init__.py'
Inspection info: This inspection detects names that should resolve but
don't. Due to dynamic dispatch and duck typing, this is possible in a
limited but useful number of cases. Top-level and class-level items
are supported better than instance items.


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: 'Psycopg2.errors' not referenced in packaged
  2020-11-19 15:41 'Psycopg2.errors' not referenced in packaged Patrick Starrenburg <[email protected]>
@ 2020-11-19 16:37 ` Daniele Varrazzo <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Daniele Varrazzo @ 2020-11-19 16:37 UTC (permalink / raw)
  To: Patrick Starrenburg <[email protected]>; +Cc: psycopg

On Thu, 19 Nov 2020 at 15:42, Patrick Starrenburg
<[email protected]> wrote:

> I am using psycopg2 in a Django app. In my code I am checking for various exceptions, one of which is foreign key violations.
>
> I see in the psycopg2 docs https://www.psycopg.org/docs/errors.html that ForeignKeyViolation
> is under the base IntegrityError exception. I would like to be able to specifically catch, and respond to the ForeignKeyViolation error. I am coding using the recommendation in the docs (below).
>
> It is working (a forced FK violation is specifically caught) my question is though that in my IDE (PyCharm) it reports that it cannot find the reference 'errors' and I cannot use dotted links to drill down to the errors.ForeignKeyViolation function.
>
> I can type psycopg2.IntegrityError and reference to it is found (and I see that it is listed in the __init.py__ file).
>
> When I Google this some say it is a PyCharm bug, some say that PyCharm is following the Python package convention.

Yes, it is a PyCharm shortcoming: the exception is there:

    >>> import psycopg2.errors
    >>> psycopg2.errors.ForeignKeyViolation
    psycopg2.errors.ForeignKeyViolation

The exceptions are defined in the C module, but they are exposed in
the errors module. If you look at the source code for the module, it
appears mostly empty: the exceptions are added there when the
psycopg2._psycopg internal module is imported.

Personally this is good enough: the module works as expected for all
Python code; supporting PyCharm is not mandatory as far as I'm
concerned. I am happy to receive patches to make PyCharm work better,
but working on it myself isn't my priority now.

-- Daniele





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2020-11-19 16:37 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-11-19 15:41 'Psycopg2.errors' not referenced in packaged Patrick Starrenburg <[email protected]>
2020-11-19 16:37 ` Daniele Varrazzo <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox