Skip to content

Commit d204f39

Browse files
committed
Tackle PR comments
1 parent 129b919 commit d204f39

File tree

1 file changed

+4
-4
lines changed
  • instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django

1 file changed

+4
-4
lines changed

Diff for: instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from django.urls import Resolver404, resolve
4545

4646
DJANGO_2_0 = django_version >= (2, 0)
47+
DJANGO_3_0 = django_version >= (3, 0)
4748

4849
if DJANGO_2_0:
4950
# Since Django 2.0, only `settings.MIDDLEWARE` is supported, so new-style
@@ -68,10 +69,9 @@ def __call__(self, request):
6869
except ImportError:
6970
MiddlewareMixin = object
7071

71-
72-
try:
72+
if DJANGO_3_0:
7373
from django.core.handlers.asgi import ASGIRequest
74-
except ImportError:
74+
else:
7575
ASGIRequest = None
7676

7777
try:
@@ -113,7 +113,7 @@ def __call__(self, request):
113113

114114

115115
def _is_asgi_request(request: HttpRequest) -> bool:
116-
return bool(ASGIRequest and isinstance(request, ASGIRequest))
116+
return ASGIRequest is not None and isinstance(request, ASGIRequest)
117117

118118

119119
class _DjangoMiddleware(MiddlewareMixin):

0 commit comments

Comments
 (0)