bug: partition_email() raises io.UnsupportedOperation on a file-like object that cannot seek
Maintainers usually reply within 6 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
Research direction
Read unstructured/partition/email.py, especially EmailPartitioningContext._validate() and the msg property, then compare how partition_json() and partition_ndjson() handle non-seekable streams as described in #4643 and #4649. Reproduce with a readable pipe or another non-seekable file-like object and compare its output with io.BytesIO containing the same email bytes. Done when partition_email(file=...) returns the same elements for both inputs.
Written by the indexing model from the issue text.
Description
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 (
mainat 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.
- Dominant language
- HTML
- Stars
- 15.8k
- Forks
- 1.4k
- Avg merge
- 8d 4h
- Merged PRs (30d)
- 40
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Unstructured-IO/unstructured
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Unstructured-IO/unstructured#4876 ·
Maintainers usually reply within 6 days
-
fix(nlp): match single-letter bullets in the enumerated bullet patternPossibly taken @Eapp1e claimed this 33 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Unstructured-IO/unstructured#4635 ·
Maintainers usually reply within 6 days
-
bug(cleaners): translate_text passes text instead of chunk in attention window loopPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 82/100
Unstructured-IO/unstructured#4558 · 1 comment ·
Maintainers usually reply within 6 days
-
extract_text_before/extract_text_after raise UnboundLocalError when the pattern is absentPossibly taken @ayam04 claimed this 103 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Unstructured-IO/unstructured#4427 · 3 comments ·
Maintainers usually reply within 6 days
-
Large HTML documents cannot be partitioned using the partition_html function.Possibly taken @CrepuscularIRIS claimed this 229 days ago. Openbug
Difficulty 1/5 Under an hour Newbie friendliness 72/100
Unstructured-IO/unstructured#4289 · 1 comment ·
Maintainers usually reply within 6 days
All issues in Unstructured-IO/unstructured
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
TigreGotico/orthography2ipa#2950 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
🐛 bug 👩💻 équipe CE
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
betagouv/conseillers-entreprises#4835 ·
Maintainers usually reply within 1 day
-
area: integrations documentation priority: P2 size: XS
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
eddiejaoude/StackDash#798 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ThinkR-open/mordew#88 ·