Skip to content

3.14: KeyError in sysmon_branch_either after use of except* #2086

@jacobtylerwalls

Description

@jacobtylerwalls

Describe the bug
Similar to #1991, a KeyError is emitted from sysmon_branch_either on Python 3.14.0 after a use of except*.

======================================================================
ERROR: test_asgi_cookies (asgi.tests.ASGITest.test_asgi_cookies)
----------------------------------------------------------------------
  + Exception Group Traceback (most recent call last):
  |   File "/Users/jwalls/.env/lib/python3.14/site-packages/django/core/handlers/asgi.py", line 196, in handle
  |     async with asyncio.TaskGroup() as tg:
  |                ~~~~~~~~~~~~~~~~~^^
  |   File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/asyncio/taskgroups.py", line 72, in __aexit__
  |     return await self._aexit(et, exc)
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/asyncio/taskgroups.py", line 174, in _aexit
  |     raise BaseExceptionGroup(
  |     ...<2 lines>...
  |     ) from None
  | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/Users/jwalls/.env/lib/python3.14/site-packages/django/core/handlers/asgi.py", line 200, in handle
    |     raise RequestProcessed
    | django.core.handlers.asgi.ASGIHandler.handle.<locals>.RequestProcessed
    +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jwalls/.env/lib/python3.14/site-packages/asgiref/sync.py", line 325, in __call__
    return call_result.result()
           ~~~~~~~~~~~~~~~~~~^^
  File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/concurrent/futures/_base.py", line 443, in result
    return self.__get_result()
           ~~~~~~~~~~~~~~~~~^^
  File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/concurrent/futures/_base.py", line 395, in __get_result
    raise self._exception
  File "/Users/jwalls/.env/lib/python3.14/site-packages/asgiref/sync.py", line 365, in main_wrap
    result = await awaitable
             ^^^^^^^^^^^^^^^
  File "/Users/jwalls/django/tests/asgi/tests.py", line 89, in test_asgi_cookies
    await communicator.wait()
  File "/Users/jwalls/.env/lib/python3.14/site-packages/asgiref/testing.py", line 58, in wait
    await self.future
  File "/Users/jwalls/.env/lib/python3.14/site-packages/django/core/handlers/asgi.py", line 166, in __call__
    await self.handle(scope, receive, send)
  File "/Users/jwalls/.env/lib/python3.14/site-packages/django/core/handlers/asgi.py", line None, in handle
  File "/Users/jwalls/.env/lib/python3.14/site-packages/coverage/sysmon.py", line 460, in sysmon_branch_either
    l1 = code_info.byte_to_line[instruction_offset]
         ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
KeyError: 916

----------------------------------------------------------------------
Ran 1 test in 0.352s

To Reproduce

Answer the questions below:

  1. What version of Python are you using? 3.14.0
  2. What version of coverage.py shows the problem? The output of coverage debug sys is helpful. 7.11.3
Full debug sys output
-- sys -------------------------------------------------------
               coverage_version: 7.11.3
                coverage_module: /Users/jwalls/coverage_repro/lib/python3.14/site-packages/coverage/__init__.py
                           core: -none-
                        CTracer: available from /Users/jwalls/coverage_repro/lib/python3.14/site-packages/coverage/tracer.cpython-314-darwin.so
           plugins.file_tracers: -none-
            plugins.configurers: -none-
      plugins.context_switchers: -none-
              configs_attempted: /Users/jwalls/django/tests/.coveragerc
                   configs_read: /Users/jwalls/django/tests/.coveragerc
                    config_file: /Users/jwalls/django/tests/.coveragerc
                config_contents: b'[run]\nbranch = True\nconcurrency = multiprocessing,thread\ndata_file = ${RUNTESTS_DIR-.}/.coverages/.coverage\nomit =\n    */django/utils/autoreload.py\nsource = django\n\n[report]\nignore_errors = True\nomit =\n    */django/conf/locale/*\n    */tests/*\n\n[html]\ndirectory = coverage_html\n'
                      data_file: -none-
                         python: 3.14.0 (v3.14.0:ebf955df7a8, Oct  7 2025, 08:20:14) [Clang 16.0.0 (clang-1600.0.26.6)]
                       platform: macOS-26.1-arm64-arm-64bit-Mach-O
                 implementation: CPython
                          build: v3.14.0:ebf955df7a8
                                 Oct  7 2025 08:20:14
                    gil_enabled: True
                     executable: /Users/jwalls/coverage_repro/bin/python
                   def_encoding: utf-8
                    fs_encoding: utf-8
                            pid: 36810
                            cwd: /Users/jwalls/django/tests
                           path: /Users/jwalls/django/tests
                                 /Library/Frameworks/Python.framework/Versions/3.14/lib/python314.zip
                                 /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14
                                 /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/lib-dynload
                                 /Users/jwalls/coverage_repro/lib/python3.14/site-packages
                    environment: BUNDLED_DEBUGPY_PATH = /Users/jwalls/.vscode/extensions/ms-python.debugpy-2025.15.2025110501-darwin-arm64/bundled/libs/debugpy
                                 HOME = /Users/jwalls
                                 PYDEVD_DISABLE_FILE_VALIDATION = 1
                                 PYTHONSTARTUP = /Users/jwalls/Library/Application Support/Code/User/workspaceStorage/ce83212064299361443b563749bd458d/ms-python.python/pythonrc.py
                                 PYTHON_BASIC_REPL = 1
                                 VSCODE_DEBUGPY_ADAPTER_ENDPOINTS = /Users/jwalls/.vscode/extensions/ms-python.debugpy-2025.15.2025110501-darwin-arm64/.noConfigDebugAdapterEndpoints/endpoint-69acd048cfc652fa.txt
                                 VSCODE_PYTHON_AUTOACTIVATE_GUARD = 1
                   command_line: /Users/jwalls/coverage_repro/lib/python3.14/site-packages/coverage/__main__.py debug sys
                           time: 2025-11-13 17:11:12
  1. What versions of what packages do you have installed? The output of pip freeze is helpful.
asgiref==3.10.0
coverage==7.11.3
Django @ file:///Users/jwalls/django
sqlparse==0.5.3
  1. What code shows the problem? Give us a specific commit of a specific repo that we can check out. If you've already worked around the problem, please provide a commit before that fix.

We isolated the triggering code to django/django@2501958 and almost certainly the line containing except*.

  1. What commands should we run to reproduce the problem? Be specific. Include everything, even git clone, pip install, and so on. Explain like we're five!
python -m venv .env
source .env/bin/activate
git clone https://github.com/django/django
cd django
git checkout 2501958b5127020411df6271445ccfd0906df70e
pip install .
pip install coverage
cd tests
python -m coverage run runtests.py asgi.tests.ASGITest.test_asgi_cookies

Expected behavior
Successful coverage run

Additional context
We isolated the triggering code to django/django@2501958 and almost certainly the line containing except*.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions