[Bug]: macOS font discovery raises KeyError('_items') for an incomplete system_profiler font record · Issue #32328 · matplotlib/matplotlib · GitHub
Skip to content

[Bug]: macOS font discovery raises KeyError('_items') for an incomplete system_profiler font record #32328

Open

Description

@iskandr

Summary

On macOS arm64, importing matplotlib.pyplot through DNA Chisel during a command-line smoke test failed in _get_macos_fonts with KeyError: '_items'. Matplotlib is 3.10.8, Python 3.12.6. The process was running with restricted filesystem access; Matplotlib could not write its default cache directory and created a temporary cache before scanning fonts.

The current implementation catches subprocess/plist parsing errors but assumes every successfully decoded record contains _items:
https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/font_manager.py

Minimal parser-boundary reproduction

In an environment where font_manager can already be imported:

import plistlib
from unittest.mock import patch
from matplotlib import font_manager

font_manager._get_macos_fonts.cache_clear()
payload = plistlib.dumps([{"_name": "Fonts"}])
with patch("subprocess.check_output", return_value=payload):
    font_manager._get_macos_fonts()

The payload is a minimal synthetic reproduction of the missing-key condition, not a capture of the entire system_profiler response. The actual CLI traceback ended at:

font_manager.py, in _get_macos_fonts
    return [Path(entry["path"]) for entry in d["_items"]]
KeyError: '_items'

Expected behavior

Treat unavailable/incomplete system font discovery as an empty or partial result, consistent with the existing OSError/subprocess-error fallbacks, rather than making pyplot import fail. A regression could cover missing _items and entries without a path.

This is a robustness report; no change to font selection semantics is requested when system_profiler returns a complete record. Downstream discovery: openvax/vaxrank#428.

Activity

  1. iccir commented on Sep 9, 2026

    @iccir
    Contributor

    Likely fixed by #31977

  2. iccir commented on Sep 10, 2026

    @iccir
    Contributor

    This specific error isn't going to occur after #31977, as we no longer use system_profiler or parse a plist. Can you provide more information about "The process was running with restricted filesystem access"? I want to ensure that our new approach using CoreText handles this case.

  3. iskandr commented on Oct 9, 2026

    @iskandr
    Author

    This remains reproducible with Matplotlib 3.11.2 on macOS / Python 3.12.6 in the Tsarina canine-report validation. A cold-cache full run had 708 passing tests and four failures ending in _get_macos_fonts -> d['_items'] -> KeyError('_items'), including one existing human plotting test. The standalone report CLI failed at the same parser boundary. No raw system-profiler/font inventory is attached.

    A matching local font cache (format 3.11.0) in an explicit writable MPLCONFIGDIR loads and renders SVG successfully; this is the temporary test-environment recovery, not a patch to Matplotlib. The source still directly indexes d['_items'] after its subprocess/plist-error handlers. Missing-key discovery should degrade to unavailable/partial system fonts rather than prevent pyplot import, as requested in the original issue.

  4. iccir commented on Oct 9, 2026

    @iccir
    Contributor

    This will not be fixed until 3.12.

    Can you please elaborate on "The process was running with restricted filesystem access" from the original description. I want to make sure that our new path in 3.12 fixes this. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions