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

Deprecation Warning: asyncio.get_event_loop() in tortoise.contrib.test.__init__.py for Python 3.12+ #1824

Open
hwangtate opened this issue Dec 24, 2024 · 0 comments

Comments

@hwangtate
Copy link

hwangtate commented Dec 24, 2024

Description

When running tests with Tortoise ORM in a Python 3.12 environment, a DeprecationWarning is raised due to the usage of asyncio.get_event_loop(). This function's behavior has changed in Python 3.10+, and as of Python 3.12, it raises a DeprecationWarning instead of returning a default loop when there is no current event loop.

Steps to Reproduce

Use Python 3.12.1 or newer.
Install Tortoise ORM version 0.23.0.
Run tests with pytest or similar tools that leverage tortoise.contrib.test.

Expected Behavior

The library should use asyncio.new_event_loop() or a similar approach to avoid the deprecation warning and ensure compatibility with Python 3.12+.

Actual Behavior

The following warning appears in the test output:

DeprecationWarning: There is no current event loop
    loop = loop or asyncio.get_event_loop()

Environment

  • Python version: 3.12.1
  • Tortoise ORM version: 0.23.0
  • Operating System: macOS

Suggested Fix

Replace the usage of asyncio.get_event_loop() with asyncio.new_event_loop() in tortoise.contrib.test.__init__.py.

For example:

loop = loop or asyncio.new_event_loop()

Alternatively, ensure that a default event loop is created and set explicitly during the testing phase.

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

No branches or pull requests

1 participant