Skip to content

[BUG]: Python 3.14 Compatibility - BaseDefaultEventLoopPolicy AttributeError #15218

@sam-stake

Description

@sam-stake

Tracer Version(s)

3.18.1

Python Version(s)

3.14.0

Pip Version(s)

25.2

Bug Report

Description

ddtrace 3.18.1 fails to import on Python 3.14.0 due to attempting to access asyncio.events.BaseDefaultEventLoopPolicy, which was made private (renamed to _BaseDefaultEventLoopPolicy) in Python 3.14.

Expected Behaviour

ddtrace should import successfully on Python 3.14, as the package metadata declares Python 3.14 support.

Actual Behaviour

Import fails with AttributeError:

AttributeError: module 'asyncio.events' has no attribute 'BaseDefaultEventLoopPolicy'

Full Traceback

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    from ddtrace.profiling.profiler import Profiler
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/ddtrace/profiling/__init__.py", line 1, in <module>
    from .profiler import Profiler
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/ddtrace/profiling/profiler.py", line 23, in <module>
    from ddtrace.profiling.collector import asyncio
  File "/path/to/ddtrace/profiling/collector/asyncio.py", line 5, in <module>
    from . import _lock
  File "/path/to/ddtrace/profiling/collector/_lock.py", line 25, in <module>
    from ddtrace.profiling.collector import _task
  File "ddtrace/profiling/collector/_task.pyx", line 7, in init ddtrace.profiling.collector._task
  File "/path/to/ddtrace/profiling/_asyncio.py", line 38, in <module>
    @ModuleWatchdog.after_module_imported("asyncio")
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/path/to/ddtrace/internal/module.py", line 699, in _
    cls.register_module_hook(module, hook)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/path/to/ddtrace/internal/module.py", line 671, in register_module_hook
    hook(module_object)
    ~~~~^^^^^^^^^^^^^^^
  File "/path/to/ddtrace/profiling/_asyncio.py", line 62, in _
    @partial(wrap, sys.modules["asyncio.events"].BaseDefaultEventLoopPolicy.set_event_loop)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'asyncio.events' has no attribute 'BaseDefaultEventLoopPolicy'

Root Cause

In Python 3.14, BaseDefaultEventLoopPolicy was renamed to _BaseDefaultEventLoopPolicy (made private with underscore prefix) as part of the asyncio policy deprecation changes.

Python 3.14 asyncio.events attributes:

# Python 3.14.0
>>> import asyncio.events
>>> [attr for attr in dir(asyncio.events) if 'Policy' in attr]
['_AbstractEventLoopPolicy', '_BaseDefaultEventLoopPolicy']

The class still exists but is now private. ddtrace needs to update its reference in:

  • ddtrace/profiling/_asyncio.py line 62

Reproduction Code

  1. Install Python 3.14.0
  2. Create a virtual environment:
    python3.14 -m venv .venv
    source .venv/bin/activate
  3. Install ddtrace:
    pip install ddtrace==3.18.1
  4. Try to import ddtrace profiler:
    python -c "from ddtrace.profiling.profiler import Profiler"

Error Logs

No response

Libraries in Use

No response

Operating System

macOS (Darwin 24.6.0) ARM64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions