Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#32588 closed Bug (invalid)

Exception handling in contrib.postgres

Reported by: Jan Holas Owned by:
Component: contrib.postgres Version:
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (5)

comment:1 by Mariusz Felisiak, 4 years ago

Resolution: invalid
Status: newclosed

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.

in reply to:  1 comment:2 by Jan Holas, 4 years ago

Replying to 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.

comment:3 by Mariusz Felisiak, 4 years ago

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

in reply to:  3 comment:4 by Jan Holas, 4 years ago

Replying to 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.

comment:5 by Mariusz Felisiak, 4 years ago

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

Many thanks.

Last edited 4 years ago by Mariusz Felisiak (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top