fix(integrations): Remove asyncio iscoroutinefunction warning#6090
fix(integrations): Remove asyncio iscoroutinefunction warning#6090cooperoptigrid wants to merge 9 commits intogetsentry:masterfrom
Conversation
|
This PR has been automatically closed. The referenced issue is already assigned to someone else. If you believe this assignment is outdated, please comment on the issue to discuss before opening a new PR. Please review our contributing guidelines for more details. |
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
alexander-alderman-webb
left a comment
There was a problem hiding this comment.
inspect.iscoroutinefunction is not a drop-in replacement for asyncio.iscoroutinefunction on old Python versions (which we support).
There's some details in this blog post: https://lucumr.pocoo.org/2016/10/30/i-dont-understand-asyncio/
There's an existing PR containing some advice on approaching the migration. Generally mirroring the respective library's version checks would be great (not just copying Django's specific handling across the whole SDK)!
| def _markcoroutinefunction(func: "_F") -> "_F": | ||
| func._is_coroutine = asyncio.coroutines._is_coroutine # type: ignore[attr-defined] | ||
| return func |
There was a problem hiding this comment.
_markcoroutinefunction is not used outside of the Django integration, so please leave it there.
There was a problem hiding this comment.
I've simply moved it back for this PR. Still digesting the other comment
b90710a to
6d83d5e
Compare
6d83d5e to
6da51e6
Compare
|
@alexander-alderman-webb Do you want me to take those changes from that PR and add those patches here and address any outstanding comments? Or were there fundamental issues blocking its merge, and I should take a different approach entirely. |
|
I've switched to using the PY313 check, as per the other comments. I've left all existing uses of |
|
Hi @cooperoptigrid. I've taken care of the integrations now in #6133, #6134 and #6135. TL;DR: to be on the safe side we want to mirror the library's handling, and it turns out that each library has a different version cut-off. We're taking this precaution because This is possibly quite rare but it's also easier for us to maintain 😅. The risk would be creating an async/sync wrapper for a function that is treated as sync/async in the library, which could cause a coroutine to never be awaited or a If you'd like, feel free to update the tests. You should be able to just convert the occurrences of |
| _iscoroutinefunction = ( | ||
| inspect.iscoroutinefunction if PY313 else asyncio.iscoroutinefunction | ||
| ) |
There was a problem hiding this comment.
Bug: The version check for asyncio.iscoroutinefunction deprecation is incorrect. It checks for Python 3.13+ (PY313) but the deprecation occurred in Python 3.12.
Severity: LOW
Suggested Fix
Update the version check to target Python 3.12 instead of 3.13. This can be done by creating and using a PY312 constant or by reverting to the previous check hasattr(inspect, "markcoroutinefunction") which correctly identifies Python 3.12 and newer.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: sentry_sdk/integrations/_asgi_common.py#L20-L22
Potential issue: The code uses a version check for Python 3.13 (`PY313`) to decide
whether to use `inspect.iscoroutinefunction` instead of the deprecated
`asyncio.iscoroutinefunction`. However, `asyncio.iscoroutinefunction` was deprecated
starting in Python 3.12. Consequently, when running on Python 3.12, the code will still
use the deprecated function, generating a `DeprecationWarning`. This negates the
intended fix of the pull request, which was to remove this warning for supported Python
versions.
Also affects:
sentry_sdk/_compat.py:16~16
Did we get this right? 👍 / 👎 to inform future reviews.
|
Thanks for those PRs @alexander-alderman-webb , makes sense now I see what you meant by mirroring the library’s approach! I’ll change the scope of this PR to simply updating test code. |
Description
Uses Django ASGI function patching to use
inspect.iscoroutinefunctioninstead ofasyncio.iscoroutinefunctionto avoid depreaction warning in 3.14.Rolled out to all uses of
asyncio.iscoroutinefunctionin the integrations package.Repro in issue doesn't raise warning with these changes. tox linters and test pass on py3.12, py3.14.
Issues
Reminders
tox -e linters.feat:,fix:,ref:,meta:)