Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace deprecated asyncio.get_event_loop() with modern approach #1865

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

Abdeldjalil-H
Copy link
Contributor

Replace deprecated get_event_loop() with get_running_loop() and fallback to new_event_loop() to fix the "no current event loop" warning in Python 3.10+ #1824

Description

This PR updates the event loop handling in the test suite by replacing the deprecated asyncio.get_event_loop() with the modern approach using get_running_loop() with a fallback to new_event_loop(). The change specifically targets the code in /tortoise/contrib/test/__init__.py.

Motivation and Context

Since Python 3.10, using asyncio.get_event_loop() triggers a deprecation warning:
DeprecationWarning: There is no current event loop

This change modernizes the code to use the recommended approach for handling event loops, eliminating the deprecation warning while maintaining functionality.

How Has This Been Tested?

Running tests

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Replace deprecated get_event_loop() with get_running_loop() and fallback
to new_event_loop() to fix the "no current event loop" warning in Python 3.10+
Copy link

codspeed-hq bot commented Jan 24, 2025

CodSpeed Performance Report

Merging #1865 will not alter performance

Comparing Abdeldjalil-H:fix/event-loop-warning (0a7fffd) with develop (960b1c1)

Summary

✅ 12 untouched benchmarks

@Abdeldjalil-H Abdeldjalil-H marked this pull request as draft January 24, 2025 21:50
@coveralls
Copy link

coveralls commented Jan 24, 2025

Pull Request Test Coverage Report for Build 13026698161

Details

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.003%) to 89.236%

Totals Coverage Status
Change from base Build 13012319268: -0.003%
Covered Lines: 6493
Relevant Lines: 7092

💛 - Coveralls

@Abdeldjalil-H Abdeldjalil-H marked this pull request as ready for review January 25, 2025 10:15
Copy link
Contributor

@waketzheng waketzheng left a comment

Choose a reason for hiding this comment

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

Use 0.24.1 (unreleased) instead of 0.24.1

@henadzit
Copy link
Contributor

@Abdeldjalil-H, can you please merge your changes with develop? We added the 0.25.0 version to the CHANGELOG by mistake, can you please move the change from there under 0.24.1? Thanks!

@Abdeldjalil-H Abdeldjalil-H force-pushed the fix/event-loop-warning branch 2 times, most recently from 7b7e908 to 1232311 Compare January 29, 2025 07:41
@Abdeldjalil-H Abdeldjalil-H force-pushed the fix/event-loop-warning branch from 1232311 to 0a7fffd Compare January 29, 2025 07:42
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.

4 participants