bug: partition_email() raises io.UnsupportedOperation on a file-like object that cannot seek

Aperta Adatta ai principianti
#4,864 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 6 giorni

@Bensonluo ci sta già lavorando.

Dal 26/11/2026.

  • #4866 di @Bensonluo — aperta

Valutazione

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

Direzione di ricerca

Leggi unstructured/partition/email.py, in particolare EmailPartitioningContext._validate() e la proprietà msg, poi confronta come partition_json() e partition_ndjson() gestiscono i flussi non riposizionabili, come descritto in #4643 e #4649. Riproduci il problema con una pipe leggibile o un altro oggetto simile a un file non riposizionabile e confrontane l'output con quello di io.BytesIO contenente gli stessi byte dell'email. Il lavoro è completato quando partition_email(file=...) restituisce gli stessi elementi per entrambi gli input.

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

Descrizione

Describe the bug

partition_email(file=...) raises io.UnsupportedOperation: File or stream is not seekable. when the file-like object is readable but cannot seek back, such as the read end of a pipe. An unbuffered handle (open(fd, "rb", buffering=0)) fails the same way with OSError: [Errno 29] Illegal seek.

EmailPartitioningContext._validate() rewinds file unconditionally with self._file.seek(0) (unstructured/partition/email.py), before the message is parsed. The partitioner reads the message once after that (self._file.read() in the msg property), so the rewind is the only thing such a stream cannot provide.

The sibling partitioners accept the same kind of stream when called directly: partition_text(), partition_html() and partition_xml() read it as it stands, partition_json() / partition_ndjson() skip the rewind for a stream that reports seekable() as False (#4643, fixed by #4649), and partition_tsv() copies it once to a temporary file.

To Reproduce

import io
import os

from unstructured.partition.email import partition_email

with open("example-docs/eml/fake-email.eml", "rb") as f:
    eml_bytes = f.read()

reader_fd, writer_fd = os.pipe()
with os.fdopen(writer_fd, "wb") as writer:
    writer.write(eml_bytes)

with os.fdopen(reader_fd, "rb") as reader:
    print(partition_email(file=reader))
    # io.UnsupportedOperation: File or stream is not seekable.

print(partition_email(file=io.BytesIO(eml_bytes)))  # the same bytes, seekable: works

Expected behavior

partition_email(file=...) partitions a stream that cannot seek the way the sibling partitioners do, returning the same elements as the same bytes read from a seekable object.

Environment Info

  • unstructured 0.27.38 (main at 2653935)
  • Python 3.12, macOS arm64

Additional context

This report is about calling partition_email(file=...) directly. #4677 describes the same error on the generic partition(file=...) entry point, where it comes from file-type detection; #4678 addresses that path.

Lingua principale
HTML
Stelle
15.8k
Fork
1.4k
Merge medio
8g 4h
PR unite (30g)
40

Preparare l'ambiente

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 Unstructured-IO/unstructured

Tutte le issue di Unstructured-IO/unstructured

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.