Skip to content
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
1 change: 1 addition & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
## Removed

- The SDK no longer supports Python 3.6. The oldest supported version is now 3.7.
- Dropped support for Django versions below 2.0.
- The `enable_tracing` option was removed. Use `traces_sample_rate=1.0` instead.
- The deprecated `push_scope` and `configure_scope` APIs have been removed. Use `with new_scope():` to push a new scope and `scope = get_current_scope()` to retrieve the current scope instead.
- Transaction profiling and related code was removed.
Expand Down
4 changes: 0 additions & 4 deletions scripts/populate_tox/releases.jsonl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sentry_sdk/integrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def iter_default_integrations(
"chalice": (1, 16, 0),
"clickhouse_driver": (0, 2, 0),
"cohere": (5, 4, 0),
"django": (1, 8),
"django": (2, 0),
"dramatiq": (1, 9),
"falcon": (1, 4),
"fastapi": (0, 79, 0),
Expand Down
54 changes: 13 additions & 41 deletions sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
except ImportError:
raise DidNotEnable("Django not installed")

from typing import TYPE_CHECKING

from sentry_sdk.integrations.django.caching import patch_caching
from sentry_sdk.integrations.django.middleware import patch_django_middlewares
from sentry_sdk.integrations.django.signals_handlers import patch_signals
from sentry_sdk.integrations.django.tasks import patch_tasks
Expand All @@ -72,13 +75,6 @@
from sentry_sdk.integrations.django.transactions import LEGACY_RESOLVER
from sentry_sdk.integrations.django.views import patch_views

if DJANGO_VERSION[:2] > (1, 8):
from sentry_sdk.integrations.django.caching import patch_caching
else:
patch_caching = None # type: ignore

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any, Callable, Dict, List, Optional, Union

Expand All @@ -93,17 +89,6 @@
from sentry_sdk.tracing import Span


if DJANGO_VERSION < (1, 10):

def is_authenticated(request_user: "Any") -> bool:
return request_user.is_authenticated()

else:

def is_authenticated(request_user: "Any") -> bool:
return request_user.is_authenticated


TRANSACTION_STYLE_VALUES = ("function_name", "url")


Expand Down Expand Up @@ -469,7 +454,7 @@ def _get_user_from_request_and_set_on_scope(request: "WSGIRequest") -> None:
elif is_lazy:
return

if user is None or not is_authenticated(user):
if user is None or not user.is_authenticated:
return

user_info = {}
Expand Down Expand Up @@ -637,7 +622,7 @@ def _set_user_info(request: "WSGIRequest", event: "Event") -> None:

user = getattr(request, "user", None)

if user is None or not is_authenticated(user):
if user is None or not user.is_authenticated:
return

try:
Expand All @@ -658,27 +643,14 @@ def _set_user_info(request: "WSGIRequest", event: "Event") -> None:

def install_sql_hook() -> None:
"""If installed this causes Django's queries to be captured."""
try:
from django.db.backends.utils import CursorWrapper
except ImportError:
from django.db.backends.util import CursorWrapper

try:
# django 1.6 and 1.7 compatability
from django.db.backends import BaseDatabaseWrapper
except ImportError:
# django 1.8 or later
from django.db.backends.base.base import BaseDatabaseWrapper

try:
real_execute = CursorWrapper.execute
real_executemany = CursorWrapper.executemany
real_connect = BaseDatabaseWrapper.connect
real_commit = BaseDatabaseWrapper._commit
real_rollback = BaseDatabaseWrapper._rollback
except AttributeError:
# This won't work on Django versions < 1.6
return
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.backends.utils import CursorWrapper

real_execute = CursorWrapper.execute
real_executemany = CursorWrapper.executemany
real_connect = BaseDatabaseWrapper.connect
real_commit = BaseDatabaseWrapper._commit
real_rollback = BaseDatabaseWrapper._rollback

@ensure_integration_enabled(DjangoIntegration, real_execute)
def execute(
Expand Down
11 changes: 1 addition & 10 deletions sentry_sdk/integrations/django/templates.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import functools
from typing import TYPE_CHECKING

from django import VERSION as DJANGO_VERSION
from django.template import TemplateSyntaxError
from django.template.base import Origin
from django.utils.safestring import mark_safe

import sentry_sdk
Expand All @@ -13,13 +13,6 @@
if TYPE_CHECKING:
from typing import Any, Dict, Iterator, Optional, Tuple

try:
# support Django 1.9
from django.template.base import Origin
except ImportError:
# backward compatibility
from django.template.loader import LoaderOrigin as Origin


def get_template_frame_from_exception(
exc_value: "Optional[BaseException]",
Expand Down Expand Up @@ -85,8 +78,6 @@ def rendered_content(self: "SimpleTemplateResponse") -> str:

SimpleTemplateResponse.rendered_content = rendered_content

if DJANGO_VERSION < (1, 7):
return
import django.shortcuts

real_render = django.shortcuts.render
Expand Down
21 changes: 4 additions & 17 deletions sentry_sdk/integrations/django/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,15 @@
import re
from typing import TYPE_CHECKING

from django.urls import get_resolver
from django.urls.resolvers import RoutePattern

if TYPE_CHECKING:
from re import Pattern
from typing import Dict, List, Optional, Tuple, Union

from django.urls.resolvers import URLPattern, URLResolver

from django import VERSION as DJANGO_VERSION

if DJANGO_VERSION >= (2, 0):
from django.urls.resolvers import RoutePattern
else:
RoutePattern = None

try:
from django.urls import get_resolver
except ImportError:
from django.core.urlresolvers import get_resolver


def get_regex(resolver_or_pattern: "Union[URLPattern, URLResolver]") -> "Pattern[str]":
"""Utility method for django's deprecated resolver.regex"""
Expand Down Expand Up @@ -61,11 +52,7 @@ def _simplify(self, pattern: "Union[URLPattern, URLResolver]") -> str:
"""
# "new-style" path patterns can be parsed directly without turning them
# into regexes first
if (
RoutePattern is not None
and hasattr(pattern, "pattern")
and isinstance(pattern.pattern, RoutePattern)
):
if hasattr(pattern, "pattern") and isinstance(pattern.pattern, RoutePattern):
return self._new_style_group_matcher.sub(
lambda m: "{%s}" % m.group(2), str(pattern.pattern._route)
)
Expand Down
12 changes: 6 additions & 6 deletions tox.ini

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading