Skip to content

Commit 8ff5063

Browse files
fix(django): Fix psycopg3
Fixes GH-3061
1 parent 84775a0 commit 8ff5063

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

sentry_sdk/integrations/django/__init__.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -695,15 +695,10 @@ def _set_db_data(span, cursor_or_db):
695695
if is_psycopg2:
696696
connection_params = cursor_or_db.connection.get_dsn_parameters()
697697
else:
698-
is_psycopg3 = (
699-
hasattr(cursor_or_db, "connection")
700-
and hasattr(cursor_or_db.connection, "info")
701-
and hasattr(cursor_or_db.connection.info, "get_parameters")
702-
and inspect.isroutine(cursor_or_db.connection.info.get_parameters)
703-
)
704-
if is_psycopg3:
698+
try:
699+
# psycopg3
705700
connection_params = cursor_or_db.connection.info.get_parameters()
706-
else:
701+
except Exception:
707702
connection_params = db.get_connection_params()
708703

709704
db_name = connection_params.get("dbname") or connection_params.get("database")

tests/integrations/django/test_basic.py

+12
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,18 @@ def get_connection_params(self):
647647
pytest.fail("A TypeError was raised")
648648

649649

650+
def test_connection_reconnect_does_not_error(sentry_init):
651+
sentry_init(integrations=[DjangoIntegration()])
652+
653+
from django.db import connections
654+
655+
if "postgres" not in connections:
656+
pytest.skip("postgres tests disabled")
657+
658+
connections["postgres"].close()
659+
connections["postgres"].connect()
660+
661+
650662
@pytest.mark.parametrize(
651663
"transaction_style,client_url,expected_transaction,expected_source,expected_response",
652664
[

0 commit comments

Comments
 (0)