[Django] #32588: Exception handling in contrib.postgres

2 views
Skip to first unread message

Django

unread,
Mar 24, 2021, 7:17:04 AM3/24/21
to django-...@googlegroups.com
#32588: Exception handling in contrib.postgres
--------------------------------------------+------------------------
Reporter: janholas | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version:
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
When using contrib.postgres extension, this extension registers handlers
that run Postgres-specific queries (feature discovery)
https://github.com/django/django/blob/main/django/contrib/postgres/signals.py#L16

If you create a connection via psycopg2 to non-Postgres database (Redshift
for example), the ProgrammingError exception should be ignored.
https://github.com/django/django/blob/main/django/contrib/postgres/signals.py#L44

The problem is that this is catching psycopg2.ProgrammingError while when
you make a new connection the exception is wrapped to
django.db.utils.ProgrammingError in
https://github.com/django/django/blob/main/django/db/utils.py#L90

so the exceptions don't match and it's propagated to whatever caller
created a connection.

--
Ticket URL: <https://code.djangoproject.com/ticket/32588>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 24, 2021, 7:36:51 AM3/24/21
to django-...@googlegroups.com
#32588: Exception handling in contrib.postgres
----------------------------------+--------------------------------------
Reporter: janholas | Owner: (none)
Type: Bug | Status: closed
Component: contrib.postgres | Version:
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

Thanks for this report, however it's not supported to use the same
connection for different kind of databases. You can add a second database
connection and use 3rd-party backend for Redshift, e.g.
`django_redshift_backend`.

--
Ticket URL: <https://code.djangoproject.com/ticket/32588#comment:1>

Django

unread,
Mar 24, 2021, 8:39:10 AM3/24/21
to django-...@googlegroups.com
#32588: Exception handling in contrib.postgres
----------------------------------+--------------------------------------
Reporter: Jan Holas | Owner: (none)
Type: Bug | Status: closed
Component: contrib.postgres | Version:
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Jan Holas):

Replying to [comment:1 Mariusz Felisiak]:


> Thanks for this report, however it's not supported to use the same
connection for different kind of databases. You can add a second database
connection and use 3rd-party backend for Redshift, e.g.
`django_redshift_backend`.

We have a separate database connection however we're still using psycopg2
to connect to Redshift which is perfectly fine as its PG compatible. The
exception handling and the comment there suggests that it's ok to use the
contrib.postgres for other features even if the underlying DB doesn't
support HStore extension.

--
Ticket URL: <https://code.djangoproject.com/ticket/32588#comment:2>

Django

unread,
Mar 24, 2021, 1:55:48 PM3/24/21
to django-...@googlegroups.com
#32588: Exception handling in contrib.postgres
----------------------------------+--------------------------------------
Reporter: Jan Holas | Owner: (none)
Type: Bug | Status: closed
Component: contrib.postgres | Version:
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Mariusz Felisiak):

Jan, Can you share a small project with database configuration?

--
Ticket URL: <https://code.djangoproject.com/ticket/32588#comment:3>

Django

unread,
Mar 29, 2021, 3:11:23 AM3/29/21
to django-...@googlegroups.com
#32588: Exception handling in contrib.postgres
----------------------------------+--------------------------------------
Reporter: Jan Holas | Owner: (none)
Type: Bug | Status: closed
Component: contrib.postgres | Version:
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Jan Holas):

Replying to [comment:3 Mariusz Felisiak]:


> Jan, Can you share a small project with database configuration?

I will try but it's gonna take me a couple of days.

--
Ticket URL: <https://code.djangoproject.com/ticket/32588#comment:4>

Django

unread,
Mar 29, 2021, 3:13:39 AM3/29/21
to django-...@googlegroups.com
#32588: Exception handling in contrib.postgres
----------------------------------+--------------------------------------
Reporter: Jan Holas | Owner: (none)
Type: Bug | Status: closed
Component: contrib.postgres | Version:
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Mariusz Felisiak):

> I will try but it's gonna take me a couple of days.

Many thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/32588#comment:5>

Reply all
Reply to author
Forward
0 new messages