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

オープン 初心者向け
#4,864 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 6 日以内に返信

@Bensonluo がすでに取り組んでいます。

2026年11月26日 から。

  • #4866 @Bensonluo による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

unstructured/partition/email.py、特にEmailPartitioningContext._validate()とmsgプロパティを読み、#4643と#4649で説明されているように、partition_json()とpartition_ndjson()がシークできないストリームをどのように扱うかを比較してください。読み取り可能なパイプ、またはシークできない別のファイル風オブジェクトで再現し、その出力を同じメールバイト列を含むio.BytesIOの出力と比較してください。両方の入力でpartition_email(file=...)が同じ要素を返せば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
HTML
スター
15.8k
フォーク
1.4k
平均マージ
8日 4時間
マージ済み PR(30日)
40

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Unstructured-IO/unstructured のほかの issue

Unstructured-IO/unstructured の issue をすべて見る

似ている issue

Backend & API Design の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。