Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Test for Psycopg3 fix #3138

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,15 +695,10 @@ def _set_db_data(span, cursor_or_db):
if is_psycopg2:
connection_params = cursor_or_db.connection.get_dsn_parameters()
else:
is_psycopg3 = (
hasattr(cursor_or_db, "connection")
and hasattr(cursor_or_db.connection, "info")
and hasattr(cursor_or_db.connection.info, "get_parameters")
and inspect.isroutine(cursor_or_db.connection.info.get_parameters)
)
if is_psycopg3:
try:
# psycopg3
connection_params = cursor_or_db.connection.info.get_parameters()
else:
except Exception:
connection_params = db.get_connection_params()

db_name = connection_params.get("dbname") or connection_params.get("database")
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/django/myapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def middleware(request):
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}

try:
import psycopg2 # noqa
import psycopg # noqa

db_engine = "django.db.backends.postgresql"
try:
Expand Down
14 changes: 14 additions & 0 deletions tests/integrations/django/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,20 @@ def get_connection_params(self):
pytest.fail("A TypeError was raised")


@pytest.mark.forked
@pytest_mark_django_db_decorator()
def test_connection_reconnect_does_not_error(sentry_init):
sentry_init(integrations=[DjangoIntegration()])

from django.db import connections

if "postgres" not in connections:
pytest.skip("postgres tests disabled")

connections["postgres"].close()
connections["postgres"].connect()


@pytest.mark.parametrize(
"transaction_style,client_url,expected_transaction,expected_source,expected_response",
[
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ deps =
cohere-latest: cohere

# Django
django: psycopg2-binary
django: psycopg[binary]
django-v{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: djangorestframework>=3.0.0,<4.0.0
django-v{2.0,2.2,3.0,3.2,4.0,4.1,4.2,5.0}: channels[daphne]
django-v{1.11,2.0,2.2,3.0,3.2}: Werkzeug<2.1.0
Expand Down
Loading