fix(django): Use inspect.iscoroutinefunction on Python 3.14+ - #6869
fix(django): Use inspect.iscoroutinefunction on Python 3.14+#6869Digenis wants to merge 2 commits into
Conversation
|
I misunderstood the contribution guidelines It turns out that maintainers don't see the drafts' workflows queued for approval. Removing draft status. |
| if sys.version_info >= (3, 14): | ||
| from inspect import iscoroutinefunction | ||
| else: |
There was a problem hiding this comment.
Any reason to not re-use the shim we already have in Django?
sentry-python/sentry_sdk/integrations/django/asgi.py
Lines 39 to 52 in 10b4f5b
There was a problem hiding this comment.
asgi.py imports django.core.handlers.asgi which doesn't exist in django < 3
sentry supports django ≥ 1.8
views.py wraps the asgi import in a try/except block
suppressing the inner import error
caused by the missing module in django < 3
to keep django ≥ 1.8 compatibility
To rely on the shim
I have to redefine the other half of the conditional iscoroutinefunction definition
inside the try/except block
which defeats the purpose of using the shim.
The "conditional import" phrase in the asgi module docstring
was, and still is, misleading people
into imagining an import within an if block.
Maybe I should rephrase it, since I'm touching this sentence in the chore commit anyway.
Examples:
This module imports
django.core.handlers.asgi(Django >= 3), so
sentry_sdk.integrations.djangoimports it via a guarded import that
handlesImportErroron older Django versions.
This module is imported from
sentry_sdk.integrations.djangousing
try/exceptto maintain compatibility with Django versions that do
not providedjango.core.handlers.asgi.
Separate commit or fixup on chore(django): Drop Python < 3.5 compatibility ?
But this alone will not be enough to address the same misunderstanding in the future
so maybe a code comment too in views.py is needed.
It's obvious what the code does but not why it's here and not there.
Duplicated from
asgi.pybecause that module is not importable on Django < 3.
There was a problem hiding this comment.
Thanks for the thorough reply. We're not actually concerned about the
from django.core.handlers.asgi import ASGIRequestimport because it's in a type checking block. Our typing environment has newer package versions so there's no risk of ImportError for ASGIRequest.
Also, the except: block exists for Python 2 compatibility (see #851). We're not concerned about Python 2 any more, so we can remove the except : 😄
Description
Fix asyncio.iscoroutinefunction deprecation warning as mentioned in #6085.
This PR touches code that had Python < 3.5 compatibility leftovers
so I dropped them in a preceding commit to reduce churn.
Issues
asyncio.iscoroutinefunctionusage in integrations raises deprecation warning on 3.14 #6085Notes
Sibling to #3027