fix(json): accept non-seekable streams while preserving legacy adapters
Description
Readable pipes currently fail when JSON/NDJSON partitioners unconditionally rewind them. The seekability guard in #4645 fixes pipes but rejects older file-like adapters that provide read() and seek() without seekable().
Skip rewind when a stream reports seekable() == False; otherwise retain the existing rewind behavior, including when the optional query is absent. Both public partitioners now accept these adapters, return the parsed content, rewind them to position zero, and leave them open.
Related Issues
Closes #4643.
Refs #4645 and @cragwolfe's review.
This is a replacement for #4645, opened separately at the author's request. It includes the original pipe fix plus the compatibility correction and expanded tests; it can be reviewed and merged independently of #4645.
Module(s) Affected
unstructured/partition/json.pyunstructured/partition/ndjson.pytest_unstructured/partition/test_json_nonseekable_streams.py
Testing
Compared with #4645 at 49b0b7fd5e618319ea1383c2c93c702b913b1b18:
- Expanded stream regressions before: 4 failed, 4 passed (
AttributeErrorfor adapters withoutseekable()). - After: 8 passed. Includes binary/text adapters across both public partitioners, parsed content, final stream position and caller ownership; real pipes explicitly remain at EOF.
- Complete runs of the four relevant test modules: 198 passed, no deselections:
DO_NOT_TRACK=1 UNSTRUCTURED_DISABLE_NOTICE=1 python -m pytest \
test_unstructured/partition/test_json.py \
test_unstructured/partition/test_ndjson.py \
test_unstructured/partition/test_json_nonseekable_streams.py \
test_unstructured/partition/common/test_json_partitioning.py -q
- Python 3.12.14, pytest 9.2.0, macOS arm64; libmagic 5.48 installed for the existing file-detection test.
make checkpassed on the sparse checkout (Ruff 0.15.10; 173 Python files), andgit diff --checkpassed.- Published tree
3e7348a269c7d59b79655423cecde4937d050a0cexactly matches tested local commitb027973f6a88afccd54e033f8057a73685d479b4.
Checklist
- Relevant regression tests and related module tests pass.
- Conventional user-facing title; contribution guidelines reviewed.
- Full repository
make testand full-checkout checks completed. - Full
pre-commit run --all-filescompleted (pre-commit is not installed in the test environment). - Remote CI and maintainer review completed.
- Maintainer applies the
buglabel.
Additional Notes
AI-assisted implementation and local verification. The public partitioner paths were exercised directly; there is no full-repository or remote-CI success claim. No dependency files, version or changelog changes.