#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)
follow-up: 2 comment:1 by , 4 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 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.
follow-up: 4 comment:3 by , 4 years ago
Jan, Can you share a small project with database configuration?
comment:4 by , 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 , 4 years ago
I will try but it's gonna take me a couple of days.
Many thanks.
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
.