open-webui/src/lib/workers
Classic298 4e4b324246
fix: skip the pyodide plt.show patch when matplotlib is not loaded (#30381)
Any Python code that only mentioned "matplotlib" (a comment, a string, or an importlib.util.find_spec("matplotlib") check) failed with ModuleNotFoundError before a single line of it ran. The plt.show() patch was applied on a plain substring match, but matplotlib is only installed when the code actually imports it, so the patch's own import crashed the run. The user's try/except could not catch it, because their code never started. The same thing broke the code editor's Python formatter on any code that imports matplotlib, since that run only installs black.

The patch now also requires matplotlib to be present in the runtime's loaded packages, in both the worker and the sandboxed iframe host. Real matplotlib code still gets inline PNG output from plt.show(), and code that merely mentions matplotlib runs unchanged.

Gating on the callers' import regex instead was also tested and still fails the formatter case, because there the code containing the import sits inside a string while only black is installed.

Fixes #29894
2026-09-23 23:51:39 -04:00
..
kokoro.worker.ts refac 2025-02-10 00:02:23 -08:00
KokoroWorker.ts enh: kokorojs call support 2025-02-09 23:54:24 -08:00
pyodide.worker.ts fix: skip the pyodide plt.show patch when matplotlib is not loaded (#30381) 2026-09-23 23:51:39 -04:00