HTML results carry a bs4 NavigableString title, so they cannot be pickled and keep the whole page in memory

Aperta
#2,929 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@chaitanya0305 ci sta già lavorando.

Dal 27/11/2026.

  • #2930 di @chaitanya0305 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend, data

Direzione di ricerca

Read the title assignments in packages/markitdown/src/markitdown/converters/_html_converter.py, _bing_serp_converter.py, _wikipedia_converter.py, and _youtube_converter.py. Convert the title to a plain string before storing it, then check that the reported HTML fixture and the supplied reproduction pickle successfully and return a plain str title from a worker.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

For HTML input, DocumentConverterResult.title is not a str. It is the bs4.element.NavigableString returned by soup.title.string. That object is still linked to the parsed document (.parent, .next_element, ...), so:

  • pickling the result walks the whole DOM, and fails with RecursionError for an ordinary page. This breaks multiprocessing / ProcessPoolExecutor workers, and any cache that pickles results.
  • for small pages that do pickle, the payload is the full tree (a 21-byte Markdown result pickles to about 2.5 KB).
  • every result keeps the full BeautifulSoup tree of the page alive for as long as the result lives.

The bundled fixture tests/test_files/test_wikipedia.html, converted as a plain HTML file, already fails to pickle.

Repro
import io
import pickle
import tracemalloc
from concurrent.futures import ProcessPoolExecutor

from markitdown import MarkItDown, StreamInfo

PAGE = (
    "<html><head><title>Report</title></head><body>"
    + "".join(f"<p>Paragraph {i}</p>" for i in range(3000))
    + "</body></html>"
).encode()


def convert(data: bytes):
    return MarkItDown().convert_stream(
        io.BytesIO(data), stream_info=StreamInfo(extension=".html")
    )


if __name__ == "__main__":
    result = convert(PAGE)
    print("title type:", type(result.title).__name__)
    try:
        pickle.dumps(result)
        print("pickle: ok")
    except RecursionError as e:
        print("pickle: RecursionError:", e)
    with ProcessPoolExecutor(1) as pool:
        try:
            print("worker:", pool.submit(convert, PAGE).result().title)
        except Exception as e:
            print("worker:", type(e).__name__, e)

Output on main (ed17895):

title type: NavigableString
pickle: RecursionError: maximum recursion depth exceeded
worker: RecursionError maximum recursion depth exceeded while calling a Python object
Expected

result.title is a plain str ("Report"), the result pickles, and the worker returns it.

Root cause

The title is taken straight from soup.title.string:

  • packages/markitdown/src/markitdown/converters/_html_converter.py:90
  • packages/markitdown/src/markitdown/converters/_bing_serp_converter.py:119
  • packages/markitdown/src/markitdown/converters/_wikipedia_converter.py:75 (returned as is when the page has no mw-content-text body)
  • packages/markitdown/src/markitdown/converters/_youtube_converter.py:104

So this affects HTML files, URL conversions of web pages, Bing result pages, and the YouTube fallback title.

Fix

Copy the value with str(...) before storing it as the title. A tested fix is ready on branch chaitanya0305:fix/html-title-plain-str.

Lingua principale
Python
Stelle
198k
Fork
15k
Merge medio
2h 16m
PR unite (30g)
9

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/markitdown

Tutte le issue di microsoft/markitdown

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.