Skip to content

Conversation

Dibbu-cell
Copy link

Description

This PR fixes the deprecation warning for asyncio.iscoroutinefunction that will be removed in Python 3.16. The function was deprecated in Python 3.12 in favor of inspect.iscoroutinefunction.

Issues

Reminders

@Dibbu-cell Dibbu-cell requested a review from a team as a code owner October 10, 2025 18:56
Comment on lines +31 to +36
iscoroutinefunction = asyncio.iscoroutinefunction # type: ignore[assignment]

def markcoroutinefunction(func):
# type: (_F) -> _F
func._is_coroutine = asyncio.coroutines._is_coroutine # type: ignore
return func

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential bug: The fallback for markcoroutinefunction uses asyncio.coroutines._is_coroutine, which was removed in Python 3.11, causing an AttributeError.
  • Description: The compatibility shim for markcoroutinefunction provides a fallback for Python versions older than 3.12. This fallback incorrectly assumes asyncio.coroutines._is_coroutine exists. However, this attribute was removed in Python 3.11. When the SDK is used with a Django ASGI application on Python 3.11, the fallback logic is triggered, leading to an AttributeError when markcoroutinefunction is called in sentry_sdk/integrations/django/asgi.py.

  • Suggested fix: The fallback implementation for markcoroutinefunction needs to be updated to not use asyncio.coroutines._is_coroutine. A different implementation that is compatible with Python versions prior to 3.12, including 3.11, should be used.
    severity: 0.85, confidence: 0.95

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace asyncio.iscoroutinefunction

1 participant